Python is a high-level, interpreted, general-purpose programming language created by Guido van Rossum and first released in 1991. It emphasizes code readability and simplicity, allowing developers to express concepts in fewer lines of code than languages like C++ or Java.
Python supports multiple programming paradigms including object-oriented, procedural, and functional programming. It is dynamically typed and garbage-collected, making it beginner-friendly while remaining powerful enough for complex applications.
Every Python journey starts with a simple print statement. Here's the classic "Hello, World!":
# This is a comment
print("Hello, World!")
# Variables and basic output
name = "Python"
version = 3.12
print(f"Welcome to {name} {version}!")
| Feature | Python | Java | C++ |
|---|---|---|---|
| Syntax | Simple, minimal | Verbose | Complex |
| Typing | Dynamic | Static | Static |
| Compilation | Interpreted | Compiled (JVM) | Compiled |
| Speed | Moderate | Fast | Very Fast |
| Learning Curve | Easy | Moderate | Hard |
| Best For | AI/ML, scripting | Enterprise apps | Systems, games |
Python has two major version lines. Python 2 reached end-of-life in January 2020. Always use Python 3 for new projects.
Download Python from python.org. On Windows, check "Add Python to PATH" during installation. Verify with:
# Check Python version
python --version # Python 3.12.x
python3 --version # on macOS/Linux
# Run Python interactively
python
# Run a script
python hello.py
# Install packages with pip
pip install requests
pip install numpy pandas matplotlib
pip list # show installed packages
Python uses indentation (whitespace) to define code blocks - no curly braces needed. This enforces clean, readable code.
# Variables - no type declaration needed
name = "Alice"
age = 25
height = 5.7
is_student = True
# Multiple assignment
x, y, z = 1, 2, 3
a = b = c = 0
# String formatting
print(f"Name: {name}, Age: {age}") # f-string (Python 3.6+)
print("Name: {}, Age: {}".format(name, age)) # .format()
# Indentation defines blocks
if age >= 18:
print("Adult") # 4 spaces indent
if age >= 65:
print("Senior") # 8 spaces for nested block
else:
print("Minor")
# Functions
def greet(name, greeting="Hello"):
return f"{greeting}, {name}!"
print(greet("Bob")) # Hello, Bob!
print(greet("Alice", "Hi")) # Hi, Alice!
# List comprehension
squares = [x**2 for x in range(1, 6)]
print(squares) # [1, 4, 9, 16, 25]
Explore 500+ free tutorials across 20+ languages and frameworks.