Home Blogs All Courses
python c OA ( Online Assessment ) Amazon Web Services (AWS) leetcode dsa algorithms java Machine learning
Get Referral
Login Sign Up

python › Python Data Types

Python Data Types Explained: int, float, str, list, tuple, set, dict & More

phoolchandra  ·  Oct 23, 2026  · Published


Every value in Python — a marks score, a name, a list of friends, a True/False answer — has a data type. The data type decides what you can do with that value: you can add two numbers, but you cannot divide a name by 2! In this blog you will master all of Python's built-in data types, mutable vs immutable types, type checking, type conversion and the classic traps interviewers ask about.

Watch the video first, then use this blog as your notes. Every section has runnable examples, and at the end you will find a "Predict the Output" quiz, practice challenges, a self-check list, interview questions and a quick summary.

How to use this blog: Open the Python shell (type python in your terminal) or any online Python editor and type every example yourself. Change the values, break the code and see what happens — that is how concepts really stick.

1. What is a Data Type?

A data type is a category of values that tells Python how to store the value and which operations are allowed on it. Python is dynamically typed: you never declare the type; Python figures it out from the value.

x = 10          # int
x = "ten"       # now the same variable holds a str - totally fine in Python
print(type(x))  # <class 'str'>

Key idea: In Python, everything is an object, and every object has a type. Use type(value) to see it.

2. Overview of Built-in Data Types

CategoryTypeExampleMutable?
Numericint42, -7, 0No
 float3.14, -0.5, 2e3No
 complex3 + 4jNo
BooleanboolTrue, FalseNo
Textstr"Python"No
Sequencelist[1, 2, 3]Yes
 tuple(1, 2, 3)No
 rangerange(5)No
Setset{1, 2, 3}Yes
 frozensetfrozenset({1, 2})No
Mappingdict{"name": "Riya"}Yes
NoneNoneTypeNoneNo
Binarybytes, bytearrayb"hi"bytes: No, bytearray: Yes
print(type(3), type(3.0), type("3"), type(True), type(None), type(3 + 4j))
# <class 'int'> <class 'float'> <class 'str'> <class 'bool'> <class 'NoneType'> <class 'complex'>

3. Numeric Types: int, float, complex

int — whole numbers of unlimited size

a = 25
big = 2 ** 100
print(big)                       # 1267650600228229401496703205376
print(1_000_000)                 # 1000000  (underscores for readability)
print(0b101, 0o17, 0xff)         # 5 15 255 (binary, octal, hexadecimal)

Unlike C or Java, Python integers never overflow — they grow as big as your memory allows.

float — decimal numbers

pi = 3.14159
speed = 2.5e3                    # 2500.0 (scientific notation)
print(0.1 + 0.2)                 # 0.30000000000000004  (!)
print(0.1 + 0.2 == 0.3)          # False
print(round(0.1 + 0.2, 2) == 0.3)  # True

Why 0.1 + 0.2 is not 0.3: Computers store floats in binary, and 0.1 cannot be represented exactly in binary (just like 1/3 = 0.333... in decimal). For money, use the decimal module.

complex — real + imaginary

z = 3 + 4j
print(z.real, z.imag)            # 3.0 4.0
print(abs(z))                    # 5.0

Arithmetic operators at a glance

OperatorMeaningExampleResult
+Add7 + 29
-Subtract7 - 25
*Multiply7 * 214
/Divide (always float)7 / 23.5
//Floor division7 // 23
%Remainder (modulus)7 % 21
**Power7 ** 249

4. Boolean: True and False

is_passed = True
print(5 > 3)                     # True
print(type(False))               # <class 'bool'>
print(True + True)               # 2   (bool is a subclass of int!)
print(isinstance(True, int))     # True

Truthy and falsy values

Every value can be tested as True or False. These are falsy; everything else is truthy:

Falsy values
False, None, 0, 0.0, "" (empty string), [], (), {}, set()
print(bool(0), bool(""), bool([]))      # False False False
print(bool(" "), bool("False"), bool(-1))  # True True True  (!)

5. String (str) — Text

s = "Python"
print(len(s))            # 6
print(s[0], s[-1])       # P n     (indexing)
print(s[1:4])            # yth     (slicing)
print(s[::-1])           # nohtyP  (reverse)
print(s.upper(), s.lower())   # PYTHON python
print("th" in s)         # True
print(s + " 3")          # Python 3

Strings are immutable: s[0] = "J" raises TypeError. Create a new string instead: "J" + s[1:].

6. Sequence Types: list, tuple, range

fruits = ["apple", "mango", "banana"]    # list - ordered, mutable
fruits.append("kiwi")
fruits[0] = "grapes"
print(fruits)            # ['grapes', 'mango', 'banana', 'kiwi']

point = (10, 20)                         # tuple - ordered, immutable
print(point[0])          # 10
# point[0] = 5   -> TypeError: 'tuple' object does not support item assignment

r = range(1, 6)                          # range - sequence of numbers
print(list(r))           # [1, 2, 3, 4, 5]

Single-item tuple trap: (5) is just the int 5 in brackets. A one-item tuple needs a comma: (5,).

7. Set — Unique, Unordered Items

nums = {1, 2, 2, 3, 3, 3}
print(nums)              # {1, 2, 3}  duplicates removed

a = {1, 2, 3}
b = {3, 4, 5}
print(a | b)             # {1, 2, 3, 4, 5}  union
print(a & b)             # {3}              intersection
print(a - b)             # {1, 2}           difference

empty = set()            # NOT {} - that creates an empty dict!

8. Dictionary (dict) — Key: Value Pairs

student = {"name": "Riya", "age": 17, "marks": [92, 88]}
print(student["name"])           # Riya
student["city"] = "Lucknow"      # add a new key
print(student.get("phone", "N/A"))   # N/A  (safe access)
print(student.keys())
print(len(student))              # 4

Keys must be immutable (str, int, tuple). Since Python 3.7, dictionaries remember insertion order.

9. NoneType — The Absence of a Value

result = None
print(result is None)    # True  (use "is", not "==", to check None)

def greet():
    print("Hi")

print(greet())           # Hi, then None - functions without return give None

10. Mutable vs Immutable — The Most Important Concept

Immutable (cannot change in place)Mutable (can change in place)
int, float, complex, bool, str, tuple, frozenset, byteslist, dict, set, bytearray
x = [1, 2, 3]
y = x            # y points to the SAME list
y.append(4)
print(x)         # [1, 2, 3, 4]   <-- x changed too!

a = [1, 2, 3]
b = a[:]         # or a.copy() - creates a NEW list
b.append(9)
print(a)         # [1, 2, 3]

Interview favourite: Variables in Python are names pointing to objects. Assigning y = x does not copy a list — both names refer to the same object. Use id(x) to see an object's identity.

11. Checking and Converting Types

x = 42
print(type(x) == int)            # True
print(isinstance(x, (int, float)))   # True  (preferred way)

print(int("25"), int(3.99))      # 25 3   (int() truncates, does not round)
print(float(5), float("2.5"))    # 5.0 2.5
print(str(100) + "5")            # 1005
print(list("abc"))               # ['a', 'b', 'c']
print(tuple([1, 2]))             # (1, 2)
print(set([1, 1, 2]))            # {1, 2}
print(int("101", 2))             # 5      (binary string to int)
ConversionExampleResult
Implicit (automatic)3 + 2.55.5 (int promoted to float)
Explicit (type casting)int("7") + 310
Not allowed"7" + 3TypeError

Quiz: Predict the Output

Don't run the code yet! Write your answers in a notebook, then check the Answers section at the end of this blog.

Q1. What is the output?

print(type(7 / 7))

Q2. What is the output?

print(7 // 2, 7 % 2)

Q3. What is the output?

print(bool("False"))

Q4. What is the output?

print(type((5)), type((5,)))

Q5. What is the output?

print(len({1, 1, 2, 2, 3}))

Q6. What is the output?

a = [1, 2]
b = a
b.append(3)
print(a)

Q7. What is the output?

print(True + 5)

Q8. What is the type of {} ?

print(type({}))

Practice Challenges

Solve these from easy to tricky:

  1. Create one variable of each type: int, float, str, bool, list, tuple, set, dict, None — and print the type of each.
  2. Take two numbers as strings ("15" and "27"), convert them and print their sum.
  3. Remove duplicates from [4, 2, 4, 1, 2, 9] using a set and print the sorted result.
  4. Create a dictionary for a book (title, author, price) and print each value on a new line.
  5. Prove that strings are immutable and lists are mutable with a small example.

Solutions for challenges 2, 3 and 4 are in the Answers section.

Self-Check: Can You Do This?

Tick off each skill once you are confident:

Frequently Asked Interview Questions

Q: What are mutable and immutable data types?
Mutable objects (list, dict, set) can be changed after creation. Immutable objects (int, float, str, tuple) cannot — any "change" creates a new object.

Q: Difference between list and tuple?
Lists are mutable and use []; tuples are immutable, use (), are slightly faster and can be used as dictionary keys.

Q: Why can't a list be a dictionary key?
Dictionary keys must be hashable, and mutable objects like lists are not hashable.

Q: What is the difference between == and is?
== compares values; is checks whether two names refer to the same object.

Q: Is Python statically or dynamically typed?
Dynamically typed (types are checked at runtime) and strongly typed (it won't silently add a str to an int).

Summary

  • Python has numeric (int, float, complex), bool, str, sequence (list, tuple, range), set, dict and None types.
  • Python is dynamically typed — the type comes from the value.
  • Mutable: list, dict, set. Immutable: int, float, str, tuple, frozenset.
  • Use type() and isinstance() to check types; int(), float(), str() to convert.
  • Watch out for float precision, (5,) tuples, {} being a dict, and shared references.

Quick Revision Cheat Sheet

ConceptSyntax / Key point
Integerx = 10
Floatx = 3.14
Stringx = "hi"
Booleanx = True
Listx = [1, 2]
Tuplex = (1, 2)
Setx = {1, 2}
Dictx = {"a": 1}
Check typetype(x), isinstance(x, int)

Answers

Quiz answers

  1. <class 'float'> – / always returns a float.
  2. 3 1
  3. True – any non-empty string is truthy.
  4. <class 'int'> <class 'tuple'>
  5. 3 – sets keep unique items.
  6. [1, 2, 3] – a and b point to the same list.
  7. 6 – True behaves like 1.
  8. <class 'dict'> – use set() for an empty set.

Challenge solutions

# Challenge 2
a = "15"
b = "27"
print(int(a) + int(b))          # 42

# Challenge 3
nums = [4, 2, 4, 1, 2, 9]
print(sorted(set(nums)))        # [1, 2, 4, 9]

# Challenge 4
book = {"title": "Python Basics", "author": "Coding Battle", "price": 299}
for value in book.values():
    print(value)

Conclusion

You now understand every built-in Python data type and the difference between mutable and immutable objects — a concept that will save you from many bugs. Next, take a deep dive into the most used data structure: Python Lists.

If this blog helped you, watch the full video above, subscribe to the channel and share it with a friend who is learning Python. Happy coding!