Python Variable Types

8. Variable Types
Python is a dynamically typed language - which means you don’t have to declare the type of variable, or need to specify variable types. Python automatically detects the type from the value type at runtime.
# Python is a dynamically typed language.
## Variable types are inferred at runtime, so you can write:
x = 5 # x is an integer
x = "hello" # now x is a string
Common Built-in Data Types
Python has several built-in types for different kinds of data or values:
- Integer (
int
) - whole numbers (e.g., 5, -10, 0) - Float (
float
) - decimal numbers (e.g., 3.14, -0.5, 2.0) - String (
str
) - text inside quotes or enclosed in quotes (e.g., “hello”, ‘Python’) - Boolean (
bool
) - logical values (True or False) - list - Ordered, mutable collection [1, 2, 3]
- tuple - Ordered, immutable collection (1, 2, 3)
- dict - Key-value pairs {“name”: “Alice”, “age”: 25}
- set - Unordered collection of unique items {1, 2, 3}
Examples:
x = 10 # int
y = 3.14 # float
z = "Hello" # str
is_ready = True # bool
You can check any variable’s type using the built-in type() function::
x = 10
print(type(x)) # Output: <class 'int'>
Output:
<class 'int'>
🧩 Try It Yourself
- Create five variables of different data types.
- Use type() to display each one’s type.
Example :
name = "Alice"
age = 30
height = 5.6
is_student = True
subjects = ["Math", "Science", "English"]
print(type(name))
print(type(age))
print(type(height))
print(type(is_student))
print(type(subjects))
Output:
<class 'str'>
<class 'int'>
<class 'float'>
<class 'bool'>
<class 'list'>
Summary
- You don’t need to declare variable types — Python infers them.
- Use
type()
to check data types. - Learn the basic built-in types — they’re the foundation of all Python programs.
Now that you understand Python variables, your next step is to learn about Assigning Values to Variables in Python in detail.