Python is a dynamically typed language, which means that the data type of a variable is inferred at runtime based on the type of the value that the variable holds. However, Python supports several built-in data types that can be used to store and manipulate different kinds of data.
Here are some of the built-in data types in Python:
- Numeric types:
- int (integer): stores whole numbers, such as 1, 2, 3, etc.
- float: stores decimal numbers, such as 3.14, 2.5, etc.
- complex: stores complex numbers with a real and imaginary part, such as 3 + 4j, 2 – 1j, etc.
- Boolean type:
- bool: stores either True or False values, which are used to represent logical values.
- Sequence types:
- list: stores an ordered collection of items, which can be of any data type.
- tuple: similar to a list, but is immutable (cannot be changed once created).
- range: stores a sequence of numbers, which can be used for looping.
- str (string): stores a sequence of characters, such as “hello”, “world”, etc.
- Mapping type:
- dict (dictionary): stores a collection of key-value pairs, which can be used to represent a mapping between two sets of data.
- Set types:
- set: stores an unordered collection of unique items, which can be of any data type.
- frozenset: similar to a set, but is immutable (cannot be changed once created).
- Other types:
- bytes: stores a sequence of bytes (integers between 0 and 255).
- bytearray: similar to bytes, but is mutable (can be changed once created).
- None: represents a null or empty value.