Python Data Types
Python supports several built-in data types. Some of the commonly used data types in Python include:
- Numeric Types:
- int: Integer values (e.g., 5, -3, 0).
- float: Floating-point values with decimal places (e.g., 3.14, -0.5).
- complex: Complex numbers in the form
a + bj
, wherea
andb
are floats andj
represents the imaginary unit (e.g., 2 + 3j).
- Sequence Types:
- str: Strings of characters (e.g., “Hello”, ‘World’).
- list: Ordered, mutable sequences of elements (e.g., [1, 2, 3], [‘apple’, ‘banana’, ‘cherry’]).
- tuple: Ordered, immutable sequences of elements (e.g., (1, 2, 3), (‘red’, ‘green’, ‘blue’)).
- Mapping Type:
- dict: Key-value pairs, also known as dictionaries (e.g., {‘name’: ‘John’, ‘age’: 25}).
- Set Types:
- set: Unordered collections of unique elements (e.g., {1, 2, 3}).
- frozenset: Immutable version of a set (e.g., frozenset({1, 2, 3})).
- Boolean Type:
- bool: Represents truth values (True or False).
- None Type:
- None: Represents the absence of a value or a null value.
These are the fundamental data types in Python. Additionally, Python allows you to create custom data types using classes and objects, which are part of object-oriented programming.