python


What is a Variable?

A variable is a name used to store data that can be used and manipulated later in a program. Think of it as a labeled box where you can store a value. In the below example: name is a variable holding a string age is a variable holding an intege

name = "Alice"
age = 25 

Python Data Types

A variable is a name used to store data that can be used and manipulated later in a program. Think of it as a labeled box where you can store a value. In the below example: name is a variable holding a string age is a variable holding an intege

. String (str)
Textual data enclosed in quotes.

python
Copy
Edit
greeting = "Hello, World!"
2. Integer (int)
Whole numbers without decimals.

python
Copy
Edit
count = 10
3. Float (float)
Numbers with decimal points.

python
Copy
Edit
price = 19.99
4. Boolean (bool)
Represents True or False.

python
Copy
Edit
is_logged_in = True

Checking a Variable's Type
Use the type() function to see the data type:


x = 100
print(type(x))  # <class 'int'>

 Type Conversion (Casting)
Sometimes you need to convert data types.

x = "10"
y = int(x)  # Now y is an integer
Common functions:

int()

float()

str()

bool()