Skip to content

    Variables, Input & Output

    Python · Beginner

    Definition

    Variables name values; input() reads text from the user and print() writes output.

    The very first step in every Python program.

    Diagram

    input → '5'int('5') → 5print(5 * 2)

    Flowchart

    Read with input()Convert type (int, float)Computeprint() result

    Example: Fast input for contests

    import io, sys
    sys.stdin = io.StringIO('3 4\n')
    a, b = map(int, input().split())
    print(a + b)

    Output: 7

    Key points

    • input() always returns str
    • sys.stdin.readline is faster for big inputs

    Interview questions

    How to print without newline?

    print(x, end='').

    More Python topics