TetSharing
Python tutorial · 22 chapters
  1. Get started
  2. Syntax and comments
  3. Variables
  4. Numbers and math
  5. Strings
  6. f-strings and formatting
  7. Booleans and logic
  8. if, elif, else
  9. Lists
  10. Tuples
  11. Dictionaries
  12. Sets
  13. for loops and range()
  14. while, break, continue
  15. Functions
  16. Default and keyword arguments
  17. Lambda and sorting keys
  18. List comprehensions
  19. Errors and exceptions
  20. Modules and imports
  21. Reading and writing files
  22. Classes and objects

Final Python quiz
Cheat sheet: python string methods
Cheat sheet: python lists dicts

Chapter 1 of 22 · By Ethan Cole · Updated November 21, 2026

Python Tutorial for Beginners: Your First Program

Python is a general-purpose programming language known for code that reads close to plain English. It is used for automation scripts, web back ends, data analysis and most of today's AI tooling. This chapter gets a program running before we explain any theory.

What a Python program is

A Python program is a plain text file, usually ending in .py. The Python interpreter reads that file from the top and executes one statement at a time. There is no separate compile step you have to run, and no main function is required: the first line of the file is the first thing that happens.

The simplest useful statement is a call to the built-in print() function. Whatever you put between the parentheses is written to the screen, followed by a new line. Text goes inside quotes; numbers and calculations do not.

Python 3 · editable

Expected output

Hello, TetSharing!
2 + 3 = 5
Python can repeat text: hahaha

Press Run above. The first time, your browser downloads Pyodide, a full Python interpreter compiled to WebAssembly, so the first run takes a few seconds. After that, runs are almost instant. Try changing the greeting or the numbers and run it again.

What happened

  • print("Hello, TetSharing!") printed the text exactly as written, without the quotes.
  • print("2 + 3 =", 2 + 3) received two values separated by a comma. Python evaluated 2 + 3 first, then printed both values with one space between them.
  • "ha" * 3 repeats a piece of text three times. Python decides what an operator does based on the types of the values around it.

Running Python on your own computer

When you want to keep your work, install Python 3 from python.org (macOS and Linux often have it already). Save code in a file such as hello.py, open a terminal in that folder and run python3 hello.py (on Windows, py hello.py). Running python3 with no file starts the interactive interpreter, where each line runs as soon as you press Enter. It is a handy calculator and a quick way to test an idea.

Common mistakes

  • Forgetting the quotes: print(Hello) makes Python look for a variable named Hello and fails with a NameError.
  • Mismatched quotes such as "Hello'. Start and end a piece of text with the same kind of quote.
  • Writing Print with a capital P. Python is case-sensitive, so Print and print are different names.

Summary

  • A Python program is a text file that runs from top to bottom.
  • print() shows values; separate several values with commas.
  • Text is written in quotes; numbers and expressions are not.

Quiz: Get started

1. What does print("Hi", 1 + 1) display?

Python evaluates 1 + 1 before printing, and print() separates its values with a single space.

2. Which statement about how Python runs a .py file is true?

The interpreter starts at line one and works downward; no main function is required.

3. Why does print(Hello) fail?

Unquoted words are names. Since no variable called Hello exists, Python raises a NameError.

Official docs

Written under the pen name Ethan Cole with AI-assisted drafting. Every code example on this page is executed by our test suite before publishing. Found a mistake? Tell us.