Variables & Data Types
The basic building blocks of any Python program.
Understanding Variables
In Python, a variable is a name you assign to a value. Think of it as a label for a box. You don't need to declare its type; Python figures it out automatically (this is called "dynamic typing").
# A variable 'name' storing a string
name = "Alice"
# A variable 'age' storing an integer
age = 30
# You can change the value and type
age = "Thirty"
Common Data Types
Python has several built-in data types:
- Text:
str(e.g., "Hello") - Numeric:
int(10),float(10.5) - Sequence:
list,tuple - Mapping:
dict - Set:
set - Boolean:
bool(True, False)
x_str = "Hello" # str
x_int = 20 # int
x_float = 20.5 # float
x_list = ["apple", "banana"] # list
x_tuple = ("apple", "banana") # tuple
x_dict = {"name": "John"} # dict
x_bool = True # bool