Python has various data types to store different kinds of data. Understanding these data types is fundamental to programming in Python. Here’s an overview of the most commonly used data types in Python.
Numeric types store numbers. Python supports integers, floating-point numbers, and complex numbers.
Example-
x = 5
y = 3.14
z = 1 + 2j
print(type(x))
print(type(y))
print(type(z))
Sequence types store multiple items in an ordered manner. The three main sequence types are strings, lists, and tuples.
Example-
string = "Hello, World!"
my_list = [1, 2, 3, 4, 5]
my_tuple = (1, 2, 3, 4, 5)
print(type(string))
print(type(my_list))
print(type(my_tuple))
Mapping types store data in key-value pairs. The primary mapping type in Python is the dictionary.
Example-
my_dict = {"name": "Alice", "age": 25, "city": "New York"}
print(type(my_dict))
print(my_dict)