Course topics

By WebNest Studio

Python Tutorial

Hello World Program in Python

Every programming journey starts with printing "Hello, World!". In Python this takes a single line, but the tiny program already teaches you how to write a source file, run it, and read the output — and how the print() function works.

In this lesson you will write Hello World in several ways, run it from a file and from the terminal, learn the main options of print(), and see how a real Python program is usually structured with a main() function.

Your First Program

Create a file named hello.py containing print("Hello, World!"), open a terminal in the same folder, and run python hello.py (or python3 hello.py on macOS/Linux). Python reads the file, executes the statement, and prints the text. No class, no main method, no semicolons are needed.

How print() Works

print() converts its arguments to strings, separates them with a space and ends with a newline. The sep parameter changes the separator, end changes what is printed at the end, and file can send output to a file or sys.stderr. Strings can use single or double quotes.

The main() Convention

Larger programs put their code in functions and call a main() function inside if __name__ == "__main__":. This block runs only when the file is executed directly, not when it is imported as a module by another file — a pattern you will see in almost every Python project.

Examples

Hello World

Python
print("Hello, World!")
Output
Hello, World!

print() with several arguments, sep and end

Python
print("Hello", "Webnest", "Studio")
print("2026", "09", "27", sep="-")
print("Loading", end="...")
print("done")
print('Single quotes work too')
Output
Hello Webnest Studio
2026-09-27
Loading...done
Single quotes work too

Structured Hello World with a main function

Python
def greet(name):
    return f"Hello, {name}! Welcome to Python."


def main():
    for name in ["Asha", "Ravi"]:
        print(greet(name))


if __name__ == "__main__":
    main()
Output
Hello, Asha! Welcome to Python.
Hello, Ravi! Welcome to Python.

Running the program from the terminal

Python
# Windows
python hello.py

# macOS / Linux
python3 hello.py
Output
Hello, World!

Common Mistakes

  • Writing Print("Hello") — Python is case-sensitive and the function is print.
  • Forgetting the quotes around text, so Python treats Hello as an undefined variable (NameError).
  • Mixing quote types: "Hello' is a syntax error.
  • Running python hello.py from a different folder than the file is in.

Key Points to Remember

  • print("Hello, World!") is a complete Python program.
  • Run files with python file.py (python3 on macOS/Linux).
  • print() accepts multiple values and the sep and end parameters.
  • Real programs use a main() function guarded by if __name__ == "__main__".

Practice the examples

Change an input, predict the result, then compare it with the output. Explain why the result changes.