Python Tutorial › Getting Started › Python Introduction

Python Introduction

BeginnerLesson 2 of 478 min read4 runnable examples

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.

Advertisement
In this lesson
  • 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 python command. 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:

Python
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))
Output
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

YearEvent
1991Guido van Rossum publishes the first version of Python
2000Python 2.0 adds list comprehensions and garbage collection of cycles
2008Python 3.0 cleans up the language and is not fully backward compatible
2020Python 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.

Advertisement

Key features of Python

FeatureWhat it means for you
Simple, readable syntaxIndentation shows the structure, so code looks the same everywhere
Dynamically typedYou do not declare types; a variable takes the type of its value
Batteries includedThe standard library handles files, JSON, CSV, dates, regex, HTTP and more
Cross-platformThe same script runs on Windows, macOS and Linux
Multi-paradigmWrite procedural, object-oriented or functional code
Huge ecosystemPyPI hosts packages such as pytest, Playwright, requests, NumPy and Pandas
Free and open sourcePython 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.

Python
value = 42print(type(value)) value = "forty-two"print(type(value))
Output
<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:

Python
import this
Output
The 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!
Note

“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.

Advertisement

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:

  1. The interpreter reads your source code and checks the syntax.
  2. It compiles the code to bytecode, a simple instruction format.
  3. The Python virtual machine executes the bytecode line by line.

You can see which interpreter is running and where with the sys module:

Python
import sys, platform print(platform.python_implementation())print(sys.version_info.major, sys.version_info.minor)
Output
CPython
3 15
Tip

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.

Advertisement

Check your understanding

Quick quiz

1. Who created Python?

2. What does “dynamically typed” mean?

3. Which version should new projects use?

Program Practice

Ready to write code? The basic programs use only variables, arithmetic and print(), so they are a good first set.

Advertisement

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.