by: Cobena Isaac

Python Variable Types

Python 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.

1
2
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:

1
2
3
4
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::

1
2
x = 10
print(type(x))   # Output: <class 'int'>

Output:

1
<class 'int'>

Try It Yourself :

  1. Create five variables of different data types.
  2. Use type() to display each one’s type.

Example :

1
2
3
4
5
6
7
8
9
10
11
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:

1
2
3
4
5
<class 'str'>
<class 'int'>
<class 'float'>
<class 'bool'>
<class 'list'>

In Summary:

  1. You don’t need to declare variable types — Python infers them.

  2. Use type() to check data types.

  3. Learn the basic built-in types — they’re the foundation of all Python programs.

Hope this tutorial has been helpful!.

To continue building your skills, your next step is to learn about How to Assign Values to Variables in Python in detail.