Notes
Categories

Data Types in Python [ English ]

< Prev Next >

1. Introduction

In Python, a data type defines the type of value that a variable can store. Since Python is a dynamically typed language, you do not need to declare the data type explicitly—Python automatically determines it.

2. Classification of Data Types

Python data types can be broadly classified into:

  1. Numeric Types
  2. Sequence Types
  3. Set Types
  4. Mapping Type
  5. Boolean Type
  6. None Type

3. Numeric Data Types

Used to store numbers.

3.1 Integer (int)

x = 10

3.2 Float (float)

y = 3.14

3.3 Complex (complex)

z = 2 + 3j

4. Sequence Data Types

Used to store a collection of items in order.

4.1 String (str)

name = "Python"

4.2 List (list)

numbers = [1, 2, 3]

4.3 Tuple (tuple)

data = (1, 2, 3)

5. Set Data Type

Set (set)

values = {1, 2, 3}

6. Mapping Data Type

Dictionary (dict)

student = {"name": "Rahul", "age": 20}

7. Boolean Data Type (bool)

x = True
y = False

8. None Data Type (NoneType)

x = None

9. Checking Data Types

Use the type() function:

x = 10
print(type(x))

Output

<class 'int'>

10. Type Conversion

Example

x = "10"
y = int(x)

print(y)

11. Summary Table

Data Type Description Example
int Integer 10
float Decimal 3.14
complex Complex number 2+3j
str String "Hello"
list Ordered, mutable [1,2,3]
tuple Ordered, immutable (1,2,3)
set Unique elements {1,2,3}
dict Key-value pairs {"a":1}
bool True/False True
NoneType No value None

12. Important Points

13. Conclusion

Data types are the foundation of Python programming. Understanding them helps in:

< Prev Next >