Last 30 Days
No notifications
Python is a high-level, interpreted programming language known for its clean syntax and readability. Created by Guido van Rossum in 1991, it's one of the most popular languages in the world.
| Feature | Description |
| Easy to Learn | Clean, English-like syntax with enforced indentation |
| Interpreted | No compilation step — run code instantly |
| Dynamically Typed | No need to declare variable types |
| Huge Ecosystem | 400,000+ packages on PyPI |
| Versatile | Web, AI/ML, data science, automation, scripting |
1. Download from [python.org](https://python.org)
2. Check the "Add Python to PATH" checkbox during installation
3. Verify: python --version
print("Hello, World!")| Concept | Example |
| print() | print("Hello") — output to console |
| input() | name = input("Enter name: ") — read user input |
| Comments | # This is a comment |
| Indentation | Python uses 4 spaces (not braces) to define blocks |
# Single-line comment
"""
Multi-line comment
(technically a docstring)
"""> Important: Indentation is not optional in Python. It defines the structure of your code. Mixing tabs and spaces causes errors.
Python is the friendliest programming language to learn first — readable enough to mistake for English, powerful enough to run NASA missions, Instagram, and most AI on the planet. If you can write a shopping list, you can write Python.
Python is an interpreted, dynamically-typed, multi-paradigm language. In plain English:
python interpreter reads your code and runs it.print("Hello, world!")One line. No main, no semicolons, no curly braces. The interpreter reads top-to-bottom and runs each statement.
.py source → bytecode (.pyc) → Python Virtual Machine → outputFirst run, Python compiles your file to bytecode (cached in __pycache__). The PVM executes that bytecode. You don't think about this day-to-day, but it's why Python is portable: the same .py file runs anywhere with a Python interpreter.
1. Install Python 3.12+ from python.org or via the Microsoft Store / Homebrew.
2. Verify: python --version (or python3).
3. Use VS Code with the Python extension. It picks up your interpreter automatically.
4. Always work inside a virtual environment: python -m venv .venv then .venv\Scripts\activate (Windows) or source .venv/bin/activate (mac/linux). Keeps project deps isolated.
Type python in a terminal and you get an interactive prompt. Type 2 + 2, hit Enter, see 4. Perfect for tiny experiments. Press Ctrl+D / Ctrl+Z to exit.
For anything bigger, use Jupyter (pip install notebook) — same idea, but cells you can re-run.
Python uses whitespace to mark blocks. There are no { }. Four spaces, every time:
if age >= 18:
print("adult") # 4 spaces in
else:
print("minor")Mix tabs and spaces and you'll get IndentationError. Configure your editor to insert 4 spaces on Tab.
1. print x instead of print(x). Python 3 made print a function. Always use parentheses.
2. Mixing tabs and spaces. Pick spaces, configure once, forget about it.
3. Forgetting the colon at the end of if / for / def / class lines.
4. Running with the system Python. Always use a virtualenv — prevents "it works on my laptop" bugs.
5. Naming files random.py or json.py. Shadows the standard library, breaks imports.
6. Ignoring the error message. Python tracebacks are descriptive — read the *last* line first; that's the actual error.
# single-line comment
"""
Multi-line string. When placed as the first statement of a module/function/class
it becomes a docstring — readable via help() and tooling.
"""PEP 8 is Python's style guide:
snake_case for variables and functions; PascalCase for classes; UPPER_SNAKE for constants.A traceback ends with the actual exception. Train yourself to read bottom-up:
Traceback (most recent call last):
File "main.py", line 3, in <module>
print(items[5])
IndexError: list index out of rangeLast line = the error class + message. Line above = where it happened. 90% of debugging is reading this carefully.
if __name__ == '__main__'def main():
print("running directly")if __name__ == '__main__':
main()
This lets a file work both as a script (python file.py) and as an importable module (from file import main). Standard pattern in every Python project.
Python 2 reached end-of-life in January 2020. Don't write new Python 2 code. Differences you'll occasionally see in old Stack Overflow answers:
print x (statement, Py2) vs print(x) (function, Py3).5 / 2 returns 2 in Py2, 2.5 in Py3.python usually means.pip, venv, uv, poetry, pytest, black, ruff, mypy.pip install . Once you've used it, you're plugged into the largest open-source ecosystem alive.1. Install Python 3.12, verify with python --version, create a virtualenv, activate it.
2. Write a one-file program that prints Hello, , takes input with input(), and runs from the command line.
3. Force an error on purpose (int("abc")); read the traceback bottom-up and explain it.
4. Add an if __name__ == '__main__': block and import the file from a second script to confirm it doesn't auto-run.