Skip to content

    Python Basics: Variables & Data Types

    Python · Beginner

    Definition

    Python variables are names bound to objects. Core types: int, float, str, bool, list, tuple, dict and set.

    These types are used in every Python program.

    Diagram

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

    Flowchart

    Create a variablePython infers typeUse operatorsConvert with int()/str()Print the result

    Example: Types in action

    age = 20
    name = 'Asha'
    print(f'{name} is {age}', type(age).__name__)

    Output: Asha is 20 int

    Key points

    • Dynamically typed
    • Lists are mutable, tuples are not
    • Indentation defines blocks

    Interview questions

    List vs tuple?

    Lists are mutable; tuples are immutable and hashable.

    What does type() return?

    The class of the object.

    More Python topics