Variables & Data Types
Variables store data. Python has strings, integers, floats, and booleans. No need to declare types — Python figures it out.
25 min•By Priygop Team•Last updated: Feb 2026
Variables in Python
In Python, you create a variable simply by assigning a value to a name. You don't need to declare a type — Python automatically determines the type. Variable names are case-sensitive (name and Name are different). Use descriptive names and snake_case style (my_name, not myName).
Python Data Types
- str — Text: 'Hello' or "World"
- int — Whole numbers: 42, -10, 0
- float — Decimal numbers: 3.14, -0.5
- bool — True or False (capital T and F)
- list — Ordered collection: [1, 2, 3]
- dict — Key-value pairs: {'name': 'Alice', 'age': 25}
- type() — Check the type of any variable
Variables Example
Example
# Creating variables (no type declaration needed!)
name = "Alice"
age = 25
height = 5.6
is_student = True
# Printing variables
print("Name:", name)
print("Age:", age)
print("Height:", height)
print("Student:", is_student)
# Check types
print(type(name)) # <class 'str'>
print(type(age)) # <class 'int'>
print(type(height)) # <class 'float'>
print(type(is_student)) # <class 'bool'>
# f-strings (modern way to format output)
print(f"Hello, my name is {name} and I am {age} years old.")Try It Yourself: Variables
Try It Yourself: VariablesPython
Python Editor
✓ ValidTab = 2 spaces
Python|15 lines|379 chars|✓ Valid syntax
UTF-8