Introduction to Python
Python is the world's most popular programming language — clean, readable, and powerful enough to run Instagram, YouTube, and NASA's scientific tools. This chapter covers what Python is, why it dominates modern development, and how to write your very first program.
What is Python?
Python is a high-level, general-purpose, interpreted programming language emphasising code readability and simplicity. Its clean syntax lets you express ideas in far fewer lines than Java or C++, making it the go-to choice for beginners and senior engineers alike.
Python is dynamically typed — no variable type declarations needed — and supports procedural, object-oriented, and functional programming paradigms. It runs unchanged on Windows, macOS, and Linux.
A Brief History of Python
Python was conceived in the late 1980s by Guido van Rossum at Centrum Wiskunde & Informatica (CWI) in the Netherlands. He started writing it in December 1989 as a hobby project — wanting a successor to ABC with exception handling.
list,
dict, str.
Key Features of Python
Each of Python's design decisions makes the language more practical, readable, and powerful. Here are the eight features that make it stand apart from every other language:
Indentation replaces curly braces. Code reads almost like plain English, making it the easiest first language to learn.
Web, AI/ML, data science, automation, scripting — Python handles every domain without switching languages.
Python is open-source with a vibrant community. Download, use, modify, and distribute it at zero cost.
Supports classes, inheritance, encapsulation, and polymorphism. Also supports functional and procedural styles.
Code executes line-by-line. Errors are caught at the exact failing line, and a REPL shell enables rapid experimentation.
No need to declare variable types. Python infers type at runtime, dramatically speeding up development.
Write once, run on Windows, macOS, Linux, and Raspberry Pi — without modifying a single line of code.
PyPI hosts over 400,000 packages. NumPy, Pandas, Django, TensorFlow, and Scikit-learn are just the beginning.
Where is Python Used?
Python's versatility means it powers some of the world's most critical systems — from the algorithms recommending your next YouTube video, to models powering ChatGPT, to scripts automating repetitive office tasks.
Python 2 vs Python 3
Python 3 is the only version you should use today. Python 2 reached end-of-life on January 1, 2020 — no security patches, no updates. Here are the key differences:
# Python 2 — reached end of life January 2020
print "Hello, World!" # print is a statement
print 10 / 3 # outputs 3 (integer division)
raw_input("Enter: ") # raw_input for strings
# Python 3 — the modern standard
print("Hello, World!") # print is a function
print(10 / 3) # outputs 3.3333... (true division)
input("Enter: ") # input() works for all types
| Feature | Python 2 | Python 3 |
|---|---|---|
print "hello" (statement) |
print("hello") (function) |
|
| Division 5/2 | 2 (integer) |
2.5 (float) |
| Strings | Separate str and unicode types | All strings Unicode by default |
| User input | raw_input() |
input() |
| Status | ❌ End-of-life Jan 2020 | ✅ Active development |
Installing Python
Python 3 is free to download from python.org. After installation, verify with
python --version in your terminal.
Windows
# 1. Go to https://python.org/downloads and download Python 3.x
# 2. Run installer — IMPORTANT: check "Add Python to PATH" ✓
# 3. Click "Install Now"
# 4. Verify in Command Prompt:
python --version
# Python 3.12.x
pip --version
# pip 24.x
macOS
# Install Homebrew if needed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Python 3:
brew install python
python3 --version
# Python 3.12.x
Linux (Ubuntu)
sudo apt update
sudo apt install python3 python3-pip
python3 --version
# Python 3.12.x
Your First Python Program
Tradition in programming says your first program should print "Hello, World!" to the screen. In Python, this is a single line of code — compared to 5–10 lines in Java or C++.
# Your very first Python program
print("Hello, World!")
# Output:
# Hello, World!
# Get user input and respond with an f-string
name = input("What is your name? ")
print(f"Hello, {name}! Welcome to Python.")
# Example run:
# What is your name? Alice
# Hello, Alice! Welcome to Python.
a = 10
b = 3
print(f"Addition: {a} + {b} = {a + b}") # 13
print(f"Subtraction: {a} - {b} = {a - b}") # 7
print(f"Multiplication: {a} * {b} = {a * b}") # 30
print(f"Division: {a} / {b} = {a / b:.4f}") # 3.3333
print(f"Floor division: {a} // {b} = {a // b}") # 3
print(f"Modulus: {a} % {b} = {a % b}") # 1
print(f"Exponent: {a} ** {b} = {a ** b}") # 1000
str — use
int() for numbers.
# to end of line.
hello.py, open terminal in same folder, then run
python hello.py (Windows) or
python3 hello.py (macOS/Linux).
Practice Python Online — Free Compilers
Don't want to install anything yet? Practice directly in your browser with these free Python environments.
- Python is a high-level, interpreted, dynamically typed, general-purpose language created by Guido van Rossum in 1991.
- Python 3 only — Python 2 reached end-of-life January 2020. Never use it for new projects.
- Key strengths: readable syntax, versatility (web, AI, data), and a massive ecosystem of 400,000+ packages.
- Python powers Instagram, Netflix, NASA, CERN — one of the most commercially valuable languages to learn.
- Install from python.org. On Windows, always check "Add Python to PATH" during setup.
-
print("Hello, World!")— a single line. That's all it takes for your first program. -
F-strings (
f"…{variable}…") are the modern way to embed values in strings. - Practice instantly in your browser using Replit, Google Colab, or online Python compiler — no local install needed.
Python was created by Guido van Rossum, a Dutch programmer, while working at Centrum Wiskunde & Informatica (CWI) in the Netherlands in the late 1980s. The first public version was released in 1991. Guido named it after the British comedy group Monty Python's Flying Circus — not the snake. He wanted a short, unique, and slightly mysterious name, and he happened to be reading Monty Python scripts at the time.
A compiled language (e.g. C, C++) translates the entire source
code into machine code before execution. A
interpreted language reads and executes code line-by-line at
runtime. Python is interpreted — the CPython interpreter reads
your .py file, converts it internally to
bytecode, and executes it immediately. This means:
- ✔ Faster to write and test — no compile step
- ✔ Errors reported at the exact failing line
- ✔ Interactive REPL shell available
- ✘ Slightly slower at runtime than compiled code
Python 2 officially reached end-of-life on January 1, 2020.
This means it receives
no security patches, no bug fixes, and no new features. The Python
Software Foundation, major cloud providers (AWS, GCP, Azure), and all popular
libraries (NumPy, Django, Flask, TensorFlow) have dropped Python 2 support
entirely. Key breaking differences in Python 3:
print became a function, division returns
floats by default, all strings are Unicode, and
raw_input() was renamed to
input(). There is no valid reason to write
new code in Python 2.
In a statically typed language (Java, C++), you must declare
the type of every variable before using it:
int x = 5;. In
dynamically typed Python, the interpreter determines the type
at runtime based on the value assigned:
x = 10 # x is int
x = "hello" # x is now str — no error!
x = 3.14 # x is now float
This speeds up development considerably — but you must be careful about
unexpected type changes. Python 3.5+ added optional
type hints (x: int = 10)
for documentation and tooling, though they are not enforced at runtime.
- Instagram — Built entirely on Django (Python web framework). Handles 1 billion+ users.
- Netflix — Uses Python for data science, recommendation algorithms, and automation scripts.
- NASA — Uses Python and SciPy for scientific data analysis, simulation, and mission control tools.
- Google — Python is one of their three official languages (alongside Java and C++). Used in Search, YouTube, and more.
- OpenAI — The entire ChatGPT and GPT model training infrastructure is built with Python and PyTorch.
10 / 3 return in Python 3?
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions and stay updated with new tutorials.