Python Data Types
Python has several built-in data types to store different kinds of values. Here are the main data types in Python:
Python has three numeric types: int, float, and complex.
x = 5 # int
y = 2.5 # float
z = 1+2j # complex
Python has three sequence types: list, tuple, and range.
my_list = [1, 2, 3] # list
my_tuple = (1, 2, 3) # tuple
my_range = range(6) # range
my_list.append(4) # Add an item
my_list[0] = 0 # Modify an item
del my_list[1] # Remove an item
Tuples are immutable, but you can create a new tuple based on the existing one.
my_tuple = my_tuple + (4,) # Create a new tuple with an additional item
Python has one text type: str (string).
my_string = "Hello, World!"
Python has one mapping type: dict (dictionary).
my_dict = {"name": "John", "age": 30}
my_dict["city"] = "New York" # Add or modify an item
del my_dict["age"] # Remove an item
Python has two set types: set and frozenset.
my_set = {1, 2, 3} # set
my_frozenset = frozenset([1, 2, 3]) # frozenset
Python has one boolean type: bool.
x = True
y = False