Python Data Types

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:

  1. 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.
  2. Boolean type:
    • bool: stores either True or False values, which are used to represent logical values.
  3. 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.
  4. Mapping type:
    • dict (dictionary): stores a collection of key-value pairs, which can be used to represent a mapping between two sets of data.
  5. 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).
  6. 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.