Skip to content

    Python Data Types

    Python · Beginner

    Definition

    Python's core types are int, float, str, bool, list, tuple, set and dict.

    Choosing the right type makes code faster and simpler.

    Diagram

    int 5str 'hi'list [1,2]dict {'a':1}

    Flowchart

    Create a valueCheck with type()Use mutable types (list, dict, set) f…Use immutable (tuple, str) for fixed …

    Example: Inspect types

    for v in [5, 2.5, 'hi', [1], (1,), {1}, {'a': 1}]:
        print(type(v).__name__)

    Output: int float str list tuple set dict

    Complexity

    dict/set lookup O(1) average · list search O(n)

    Key points

    • Only immutable types can be dict keys
    • Sets remove duplicates

    Interview questions

    List vs tuple?

    Lists are mutable; tuples are immutable and can be dict keys.

    More Python topics