Lessons
Courses

Data Types in Python [ English ]

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)

  • Whole numbers (positive or negative)
x = 10

3.2 Float (float)

  • Decimal numbers
y = 3.14

3.3 Complex (complex)

  • Numbers with real and imaginary parts
z = 2 + 3j

4. Sequence Data Types

Used to store a collection of items in order.

4.1 String (str)

  • Sequence of characters
name = "Python"

4.2 List (list)

  • Ordered and mutable collection
numbers = [1, 2, 3]

4.3 Tuple (tuple)

  • Ordered but immutable collection
data = (1, 2, 3)

5. Set Data Type

Set (set)

  • Unordered collection of unique elements
values = {1, 2, 3}

6. Mapping Data Type

Dictionary (dict)

  • Collection of key-value pairs
student = {"name": "Rahul", "age": 20}

7. Boolean Data Type (bool)

  • Represents logical values
x = Truey = False

8. None Data Type (NoneType)

  • Represents absence of value
x = None

9. Checking Data Types

Use the type() function:

x = 10print(type(x))

Output

<class 'int'>

10. Type Conversion

Example

x = "10"y = int(x) print(y)

11. Summary Table

Data TypeDescriptionExample
intInteger10
floatDecimal3.14
complexComplex number2+3j
strString"Hello"
listOrdered, mutable[1,2,3]
tupleOrdered, immutable(1,2,3)
setUnique elements{1,2,3}
dictKey-value pairs{"a":1}
boolTrue/FalseTrue
NoneTypeNo valueNone

12. Important Points

  • Python automatically detects data types
  • Variables can change type dynamically
  • Use type() to check data type
  • Each data type has specific properties and uses

13. Conclusion

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

  • Storing and manipulating data
  • Writing efficient programs
  • Avoiding type-related errors