📢
Admissions Open for August 2026 Batch | Free Career Counselling | Limited Scholarships
Register Now →

Learning Guides

Data Types in Python: Complete Guide

Quick answer: Learn Python's core data types including int, float, string, boolean, list, tuple, dictionary and set, with type checking and conversion examples.

Overview of Python Data Types

TypeExampleMutable?
int10N/A (immutable value)
float10.5N/A (immutable value)
str"Fireblaze"No
boolTrue, FalseN/A
list[1, 2, 3]Yes
tuple(1, 2, 3)No
dict{"a": 1}Yes
set{1, 2, 3}Yes

Numeric Types

age = 25          # int
price = 89000.50  # float
complex_num = 2 + 3j   # complex, rarely needed outside specialised maths

Strings

name = "Fireblaze AI School"
print(type(name))   # 

Boolean

is_active = True
is_deleted = False
print(type(is_active))   # 

Booleans are technically a subtype of int in Python, where True behaves as 1 and False behaves as 0 in arithmetic.

Collection Types

scores = [85, 90, 78]        # list: ordered, mutable
point = (4, 5)                # tuple: ordered, immutable
student = {"name": "Priya", "age": 22}   # dict: key-value pairs
unique_ids = {101, 102, 103}  # set: unordered, no duplicates

Checking a Variable's Type

x = 10
print(type(x))          # 
print(isinstance(x, int))   # True

Type Conversion

age_str = "25"
age_int = int(age_str)     # 25 (as an integer)

price = 89000
price_str = str(price)     # "89000" (as a string)

value = "3.14"
value_float = float(value)  # 3.14

Converting a non-numeric string, such as int("abc"), raises a ValueError, so real-world code should validate the string first or handle the exception.

Mutable vs Immutable Types

Immutable types, such as int, float, str and tuple, cannot be changed in place. Any operation that appears to modify them actually creates a new object. Mutable types, such as list, dict and set, can be changed in place without creating a new object.

Common Interview Questions

What is the difference between a mutable and an immutable type?

A mutable type's contents can be changed in place after creation, such as a list. An immutable type cannot be changed, so any apparent modification actually creates a new object, such as with strings.

How would you check a variable's data type at runtime?

Use the built-in type() function, or isinstance() when checking against a specific expected type.

FAQ

Frequently Asked Questions

What are Python's core data types?

int, float, str and bool for single values, and list, tuple, dict and set for collections of values.

What is the difference between a mutable and an immutable data type?

A mutable type, like a list, can be changed in place after creation. An immutable type, like a string or tuple, cannot, so any modification creates a new object.

How do you convert a string to an integer in Python?

Use the int() function, such as int('25'), which raises a ValueError if the string does not represent a valid whole number.

Is a boolean a separate type from an integer in Python?

Technically bool is a subtype of int, so True behaves as 1 and False behaves as 0 in arithmetic operations.

Want This Mapped to Your Own Background?

A free counselling session will tell you which path fits, and will tell you honestly if none of ours does.

Book Free Career Counselling

Keep Reading

Related Articles