Basic Data Types in Python
1. Numeric Types
o int – Integer (e.g., 5, -10, 1000)
o float – Floating point number (e.g., 3.14, -0.001)
o complex – Complex numbers (e.g., 2 + 3j)
2. Boolean Type
o bool – Boolean values: True or False
3. Text Type
o str – String (e.g., 'Hello', "Python")
4. Sequence Types
o list – Ordered, mutable collection (e.g., [1, 2, 3])
o tuple – Ordered, immutable collection (e.g., (1, 2, 3))
o range – Immutable sequence of numbers (e.g., range(5))
5. Set Types
o set – Unordered, mutable, no duplicates (e.g., {1, 2, 3})
o frozenset – Immutable version of a set
6. Mapping Type
o dict – Key-value pairs (e.g., {"name": "Alice", "age": 25})
7. None Type
o NoneType – Represents the absence of a value (just None)
Use of type() Function in Python
The type() function is used to:
• Check the data type of a variable or value.
• Get the class/type of an object.
Syntax:
type(object)
Examples:
print(type(10)) # <class 'int'>
print(type("Hello")) # <class 'str'>
print(type([1, 2, 3])) # <class 'list'>
print(type(3.14)) # <class 'float'>