Python Tutorial 0/52 lessons ~6 min read Lesson 4

    Hello World

    Your first Python program is one line: print('Hello, World!').

    Course progress0%
    Focus
    8 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Your first Python program is one line: print('Hello, World!'). No boilerplate, no main function required — just save and run.

    Understanding the topic

    Core concepts to understand:

    • print() writes to stdout.
    • Strings can use single or double quotes.
    • Run with python file.py.

    Syntax reference

    Visual flow / code:

    python
    # hello.py
    print("Hello, World!")
    print(f"1 + 1 = {1 + 1}")
    # Run
    $ python hello.py
    Hello, World!
    1 + 1 = 2

    Execution workflow

    1Hello World Workflow
    1 / 3

    print() writes to stdout

    print() writes to stdout.

    Real-world use

    Python's lack of ceremony is why scripts and prototypes ship in minutes, not hours.

    Best practices

    • Use f-strings for formatting.
    • Files end in .py.
    • Add a shebang for executable scripts: #!/usr/bin/env python3.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    3 questions
    1BeginnerQuestionHow do you run a Python file?+

    Answer

    Run python hello.py (or python3 hello.py on systems where python is not mapped), or python -m package.module to run a module by import path. On Unix you can also add a shebang line and make the file executable. Inside the script, if __name__ == '__main__': guards code that should only run when the file is executed directly.

    Follow-up

    What is the difference between python file.py and python -m module?
    2BeginnerQuestionWhat's an f-string?+

    Answer

    An f-string is a string literal prefixed with f that evaluates expressions inside {} at runtime and inserts the formatted result, for example f'{name!r:>10}'. It supports format specs and the !r, !s conversions, and = for debug output like f'{x=}'. Since Python 3.12 you can reuse the same quote type and nest expressions more freely inside the braces.

    Follow-up

    How would you print a float with two decimals in an f-string?
    3BeginnerQuestionWhy no semicolons?+

    Answer

    Python does not require semicolons because a newline normally ends a statement, which keeps code visually clean. Your premise is slightly off though: semicolons are legal and can separate several simple statements on one line, such as a = 1; b = 2. Style guides discourage that, and compound statements like if cannot be put after a semicolon.

    Summary

    In summary: Zero-ceremony scripts. f-strings are the modern default.

    Ready to mark this lesson complete?Track your journey across the entire course.