Python supports several data types that are used to store and manipulate different kinds of data. Here are the main data types in Python:
- Numeric Types:
- int: Integer numbers, e.g., 10, -5, 1000.
- float: Floating-point numbers, e.g., 3.14, -0.001, 2.5e2 (scientific notation).
- Sequence Types:
- str: Strings, e.g., “hello”, ‘world’, “Python”.
- list: Ordered collection of items, e.g., [1, 2, 3], [‘apple’, ‘banana’, ‘orange’].
- tuple: Immutable ordered collection of items, e.g., (1, 2, 3), (‘a’, ‘b’, ‘c’).
- Mapping Type:
- dict: Collection of key-value pairs, e.g., {‘name’: ‘John’, ‘age’: 30, ‘city’: ‘New York’}.
- Set Types:
- set: Unordered collection of unique items, e.g., {1, 2, 3}, {‘apple’, ‘banana’, ‘orange’}.
- frozenset: Immutable set, similar to set but cannot be modified after creation.
- Boolean Type:
- bool: Represents truth values, either True or False.
- None Type:
- None: Represents absence of a value or null.
These are the built-in data types in Python. Additionally, Python allows defining custom data types using classes, which can represent more complex structures and behaviors. Python’s dynamic typing system allows variables to hold values of any data type, and type conversion functions are available to convert values between different data types when necessary.