Sobes.tech
Senior

What data types are available in Python? How are they categorized?

sobes.tech AI

Answer from AI

In Python, data types can be divided into several groups:

  1. Numeric types:

    • int — integers, for example, 42
    • float — floating-point numbers, for example, 3.14
    • complex — complex numbers, for example, 1+2j
  2. Boolean type:

    • bool — takes values True or False
  3. Sequences:

    • str — strings, for example, "hello"
    • list — mutable lists, for example, [1, 2, 3]
    • tuple — immutable tuples, for example, (1, 2, 3)
  4. Sets:

    • set — mutable set of unique elements
    • frozenset — immutable set
  5. Mappings:

    • dict — dictionaries, key-value pairs, for example, {"key": "value"}
  6. Other types:

    • NoneType — type of the object None

Example usage:

x = 10          # int
pi = 3.1415     # float
flag = True     # bool
name = "Anna"  # str
items = [1, 2, 3]  # list
point = (10, 20)    # tuple
settings = {"theme": "dark"}  # dict