Python language fundamentals: what Python is, its features and your first program
Advertisement
If you are choosing a first programming language, Python is the one most teachers recommend, and for good reasons. It reads almost like English, it lets you do real work in a few lines, and the same language is used for websites, data analysis, automation, scripting and artificial intelligence. This post explains what Python is, where it came from, what makes it different from older languages, where it is used, and how to install it and run your first programs. Every code sample was run on Python 3.9; newer versions give the same results.
What is Python?
Python is a general-purpose, high-level, interpreted programming language. Taking those words one at a time:
- General-purpose means it is not limited to one kind of task. You can build web sites, analyse data, control hardware, write games or automate boring office work with the same language.
- High-level means you describe what you want without managing computer memory or machine instructions yourself.
- Interpreted means a program called the interpreter reads your code and runs it directly, one statement at a time, without a separate compile-and-link step before every run.
Python is free and open source. You can download it, use it for any purpose, and read its source code.
A short history
| Year | Event |
|---|---|
| Late 1980s | Guido van Rossum, working in the Netherlands, starts designing Python as a hobby project; development begins in December 1989 |
| 1991 | First public release (version 0.9.0) |
| 1994 | Python 1.0 |
| 2000 | Python 2.0 adds list comprehensions and garbage collection of cycles |
| 2008 | Python 3.0 is released; it fixes design problems and is not fully compatible with Python 2 |
| 2020 | Python 2 reaches its official end of life on 1 January |
The name has nothing to do with snakes. Guido was reading the scripts of the British comedy series Monty Python's Flying Circus and chose the name. That is why Python documentation is full of jokes about spam and parrots. Today, always learn and use Python 3.
Why Python looks different
The classic way to compare languages is the first program: print a greeting. Here is the same job in three languages.
Java:
public class FirstProgram {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
C:
#include <stdio.h>
int main(void) {
printf("Hello World\n");
return 0;
}
Python:
print("Hello World")
The Python version is one line. There is no class to declare, no main function to define, no headers to include and no semicolons. The program runs the moment you start it, and it prints:
Hello World
That brevity continues throughout the language. Reading the lines of a file and counting them is a few statements; the same task in Java often needs several times more code. Less code means fewer places for bugs and faster learning.
Main features of Python
Simple and readable. Python's syntax is close to plain English. Code blocks are marked by indentation (spaces at the start of a line) instead of curly brackets:
age = 20
if age >= 18:
print("adult")
else:
print("minor")
Dynamically typed. You do not declare a variable's type. The type belongs to the value, and a name can later point to a value of another type:
x = 10
print(type(x)) # <class 'int'>
x = "ten"
print(type(x)) # <class 'str'>
x = [1, 2, 3]
print(type(x).__name__, len(x)) # list 3
Python still checks types when an operation runs: "5" + 5 raises a TypeError. It does not silently guess.
try:
"5" + 5
except TypeError as e:
print(e) # can only concatenate str (not "int") to str
Interpreted, with an interactive mode. You can type a line and see the answer at once in the REPL (read, evaluate, print, loop), which is ideal for learning. Start it by typing python3 in a terminal (python on Windows), then try 2 + 3 and press Enter to see 5.
Multi-paradigm. You can write simple scripts, organise code with functions, or use full object-oriented programming. Functional ideas such as map, filter and lambda are available too.
Batteries included. Python's standard library is large: reading files, JSON, dates, regular expressions, web requests, a small database (SQLite), a basic web server and more are available with a single import. Thousands of extra packages install with pip.
import json, datetime, math
print(json.dumps({"a": 1}), datetime.date(2026, 10, 24).strftime("%A"), math.sqrt(144))
# {"a": 1} Saturday 12.0
Automatic memory management. You never allocate or free memory. Python does it for you and removes objects nobody uses.
Portable. The same program runs on Windows, macOS and Linux without changes, as long as Python is installed.
Extensible and embeddable. You can write slow, performance-critical parts in C and call them from Python (this is how libraries like NumPy are fast), and other programs can embed Python as a scripting language.
Python's limitations
No language is best at everything, and honest beginners should know where Python is weaker:
- Speed. Python is slower than C, C++ or Java for heavy number crunching in plain loops. Libraries written in C (NumPy, pandas) make up for this in data work, and for most programs, the time is spent waiting for files, networks or people rather than the CPU.
- Mobile apps and games. Python is not the usual choice for native Android or iOS apps or for high-end 3D games.
- Memory use. Python objects take more memory than the equivalent data in C.
- Runtime errors. Because types are checked while the program runs, some mistakes appear only when that line executes. Tests and type hints reduce the risk.
- Parallel threads. In the standard CPython interpreter, only one thread runs Python code at a time (the global interpreter lock), so CPU-bound programs use processes instead. The multithreading post explains this.
Where Python is used
| Area | What people build | Common tools |
|---|---|---|
| Web development | Websites, APIs, back ends | Django, Flask, FastAPI |
| Data analysis | Reports, charts, cleaning data | pandas, NumPy, Matplotlib |
| Machine learning and AI | Predictions, language and image models | scikit-learn, PyTorch, TensorFlow |
| Automation and scripting | Renaming files, sending reports, scraping | standard library, requests |
| Testing and DevOps | Test suites, deployment scripts | pytest, Ansible |
| Education and science | Teaching, simulations, research | Jupyter, SciPy |
| Internet of Things | Sensors and small boards | MicroPython, Raspberry Pi |
Python is used inside many large companies and research labs, which is part of why jobs asking for it are plentiful. This post does not list specific companies, because those choices change.
Installing Python
- Go to the official download page at python.org and download the latest Python 3 installer for your system.
- Windows: run the installer and tick "Add Python to PATH" before clicking Install. This one checkbox prevents the most common beginner problem.
- macOS: use the installer from python.org (or Homebrew:
brew install python). - Linux: Python is usually preinstalled; if not, use your package manager, for example
sudo apt install python3.
Check the installation in a terminal:
$ python3 --version
Python 3.9.6
(On Windows the command is usually python --version.) Your number may be higher; any Python 3 version from the last few years works for everything in this series. You also get pip, the package installer: pip3 --version shows it.
For writing code you can use a plain text editor, but a code editor such as Visual Studio Code with the Python extension, or the IDLE editor that comes with Python, makes it comfortable with colours, error highlighting and a run button.
Running Python code
There are three ways, and you will use all of them.
1. The interactive prompt (REPL). Great for trying a single idea:
$ python3
>>> 2 + 3
5
>>> name = "Asha"
>>> name.upper()
'ASHA'
>>> exit()
2. A script file. Save this as hello.py:
name = "Asha"
print("Hello,", name)
print("2 + 3 =", 2 + 3)
Then run it with python3 hello.py:
Hello, Asha
2 + 3 = 5
3. An editor or notebook. Editors have a "Run" button, and notebooks (Jupyter) run code in cells and show results below each one, which is popular in data work.
You can also try small snippets right now in the browser, with no installation, in the free Python course on this site.
How a Python program runs
When you run python3 hello.py, the interpreter first compiles your source into a compact intermediate form called bytecode (stored in __pycache__ folders as .pyc files), then the Python Virtual Machine executes that bytecode one instruction at a time. You can look at bytecode with the dis module:
import dis
dis.dis("a + b")
The output lists instructions such as LOAD_NAME a, LOAD_NAME b and BINARY_ADD (Python 3.11 and newer call it BINARY_OP). You never need to manage this, but it explains why Python is called interpreted yet still leaves .pyc files behind.
Your first useful programs
A program that asks for a name and a birth year and works out an age:
name = input("Name: ")
year = int(input("Birth year: "))
print(f"Hello {name}, you are about {2026 - year} years old.")
With the answers Asha and 1998, it printed Hello Asha, you are about 28 years old.
A program that sums the even numbers from 1 to 100:
total = 0
for n in range(1, 101):
if n % 2 == 0:
total += n
print(total)
It printed 2550. A one-line version with a built-in does the same job:
print(sum(range(2, 101, 2))) # 2550
And a tiny program that counts words, using a dictionary:
text = "to be or not to be"
counts = {}
for word in text.split():
counts[word] = counts.get(word, 0) + 1
print(counts) # {'to': 2, 'be': 2, 'or': 1, 'not': 1}
Do not worry if some of these constructs are new. They are the subject of the next lessons.
Comments and style
A # starts a comment, which Python ignores. Use comments to explain why, not to repeat what the code obviously does. Python's official style guide, PEP 8, recommends four spaces for indentation, lower-case names with underscores for variables and functions (total_price), and CapitalWords for classes. Run import this in the REPL to see "The Zen of Python", a short poem of the language's design principles, including "Readability counts" and "Simple is better than complex".
Common beginner mistakes
- Skipping "Add Python to PATH" on Windows, then seeing "python is not recognized".
- Mixing tabs and spaces, or changing indentation within a block (
IndentationError). - Learning with Python 2 tutorials;
print "hello"without brackets is Python 2 syntax and fails in Python 3. - Naming a file
random.pyormath.py, which shadows the library of the same name. - Forgetting that
input()returns text, not a number. - Typing code instead of running it. Read less, run more.
What to learn next
Now that you know what Python is and how to run it, continue with the basics: identifiers, keywords, data types and type conversion, then operators, input and output and flow control. A Python cheat sheet keeps the syntax on one page, and the free video course takes you step by step from installation to databases.