An overview of Python programming language, its syntax, data types, variables, and basic operations.
Introduction to Python Programming
Quick‑reference guide for beginners
| Feature | Description |
|---|---|
| High‑level | Abstracts away low‑level details (memory management, pointers). |
| Interpreted | Code is executed line‑by‑line by the Python interpreter; no separate compile step. |
| Dynamic typing | Variable types are inferred at runtime. |
| Multi‑paradigm | Supports procedural, object‑oriented, and functional styles. |
| Extensive standard library | “Batteries‑included” modules for file I/O, networking, web, data, etc. |
| Cross‑platform | Runs on Windows, macOS, Linux, and many embedded systems. |
Install Python
python --version (or python3 --version on Unix).Choose an editor / IDE
Virtual environments (recommended)
# Create
python -m venv myenv
# Activate
# Windows
myenv\Scripts\activate
# macOS / Linux
source myenv/bin/activate
# Install packages
pip install numpy pandas
print("Hello, World!")
| Type | Literal Example | Common Operations |
|---|---|---|
int |
42 |
+ - * // % ** |
float |
3.14 |
+ - * / ** |
str |
"text" |
concatenation +, formatting |
bool |
True / False |
logical and, or, not |
list |
[1, 2, 3] |
indexing, slicing, append, pop |
tuple |
(1, 2) |
immutable sequence |
dict |
{'key': 'value'} |
key‑value lookup |
set |
{1, 2, 3} |
membership, set ops |
# Conditional
if score >= 90:
grade = 'A'
elif score >= 80:
grade = 'B'
else:
grade = 'C'
# Loop – for (iterates over any iterable)
for i in range(5): # 0,1,2,3,4
print(i)
# Loop – while
count = 0
while count < 5:
print(count)
count += 1
def greet(name: str, times: int = 1) -> None:
"""Print a greeting `times` times."""
for _ in range(times):
print(f"Hello, {name}!")
greet("Alice", 3)
return to send a value back.