Python Introduction
Python is a general-purpose programming language known for code that is short and easy to read. This lesson explains what Python is, why it is so popular, and what happens when you run a Python program.
- What Python is and who made it
- The features that make Python popular
- Where Python is used
- How the interpreter runs your code
What is Python?
Python is a high-level, interpreted, general-purpose programming language.
- High-level means you work with ideas such as lists, text and files, not with memory addresses.
- Interpreted means you run the source file directly with the
pythoncommand. There is no separate compile step to manage. - General-purpose means it is not tied to one job. The same language builds web servers, test frameworks and data reports.
Here is a complete Python program. It stores some test results and prints a summary:
results = {"login": "pass", "search": "pass", "checkout": "fail"} passed = [name for name, status in results.items() if status == "pass"]print("Tests run:", len(results))print("Passed:", ", ".join(passed))Tests run: 3 Passed: login, search
You do not need to understand every line yet. Notice how little punctuation there is: no semicolons, no curly braces around blocks, no type declarations.
A short history
| Year | Event |
|---|---|
| 1991 | Guido van Rossum publishes the first version of Python |
| 2000 | Python 2.0 adds list comprehensions and garbage collection of cycles |
| 2008 | Python 3.0 cleans up the language and is not fully backward compatible |
| 2020 | Python 2 reaches end of life on 1 January; all new code uses Python 3 |
The name comes from the comedy group Monty Python, not from the snake.
Key features of Python
| Feature | What it means for you |
|---|---|
| Simple, readable syntax | Indentation shows the structure, so code looks the same everywhere |
| Dynamically typed | You do not declare types; a variable takes the type of its value |
| Batteries included | The standard library handles files, JSON, CSV, dates, regex, HTTP and more |
| Cross-platform | The same script runs on Windows, macOS and Linux |
| Multi-paradigm | Write procedural, object-oriented or functional code |
| Huge ecosystem | PyPI hosts packages such as pytest, Playwright, requests, NumPy and Pandas |
| Free and open source | Python is developed by the Python Software Foundation and the community |
Dynamic typing in action: the same name can hold values of different types, and type() tells you what it holds right now.
value = 42print(type(value)) value = "forty-two"print(type(value))<class 'int'> <class 'str'>
The Zen of Python
Python’s design ideas are written down as a short poem. Run import this to print it:
import thisThe Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!
“Readability counts” and “Simple is better than complex” are the two lines you will feel most while learning. Python code is read far more often than it is written.
What is Python used for?
- Test automation: pytest, Selenium, Playwright and requests for UI and API testing.
- Web development: Django, Flask and FastAPI power web sites and REST APIs.
- Data analysis: NumPy, Pandas and Matplotlib turn raw data into answers.
- Machine learning and AI: scikit-learn, PyTorch and TensorFlow.
- Scripting and automation: renaming files, sending reports, cleaning spreadsheets.
- DevOps and cloud tooling: Ansible, AWS and Azure SDKs, CI scripts.
How Python runs your code
When you run python hello.py:
- The interpreter reads your source code and checks the syntax.
- It compiles the code to bytecode, a simple instruction format.
- The Python virtual machine executes the bytecode line by line.
You can see which interpreter is running and where with the sys module:
import sys, platform print(platform.python_implementation())print(sys.version_info.major, sys.version_info.minor)CPython 3 15
The standard interpreter is called CPython because it is written in C. Other implementations exist, such as PyPy (faster for long-running code) and Pyodide, which runs Python in a browser and powers the Try it buttons on this site.
Check your understanding
Quick quiz
1. Who created Python?
Guido van Rossum released Python in 1991. James Gosling created Java and Dennis Ritchie created C.
2. What does “dynamically typed” mean?
In Python you write x = 5 and x holds an int; assign a string later and it holds a str.
3. Which version should new projects use?
Python 2 reached end of life in January 2020. Python 3 is the only supported version.
Program Practice
Ready to write code? The basic programs use only variables, arithmetic and print(), so they are a good first set.
40 Python Basic Programs
Every program has a step-by-step explanation, colour-coded code and its real output.
Python introduction FAQ
Is Python a compiled or interpreted language?
Both, in a sense. CPython compiles your source to bytecode and then interprets that bytecode. You only ever run one command, python file.py, so it feels interpreted.
Is Python good for beginners?
Yes. Its syntax is short and readable, error messages point to the exact line, and you can get useful results with very little code.
Is Python free?
Yes. Python is open source and free to use for personal and commercial projects.
What is the difference between Python and Java?
Java is statically typed and compiled to JVM bytecode ahead of time; Python is dynamically typed and run directly. Python programs are usually shorter, while Java catches more type errors before the program runs.