1.1 What is Python?
Python is a powerful, high-level programming language designed with a focus on simplicity, readability, and versatility. It is used across various domains — from web development and data science to automation, artificial intelligence, and more.
Python lets you build more with less code. It’s often called the “Swiss Army Knife” of programming languages.
✅ Example:
# Simple Python program print("Hello, World!")
🔑 Key Points:
- Easy to read and write
- Free and open-source
- Runs on all platforms (Windows, Mac, Linux)
- Great for beginners and experts alike
- Huge ecosystem of libraries (e.g., NumPy, Flask, Django)
- Used by top companies like Google, Netflix, and NASA
- Backed by a massive global community
1.2 The Very Basics
Python emphasizes code clarity. It uses indentation to define blocks instead of braces or keywords — making the code look neat and clean by default.
Python code often feels like writing English instructions.
✅ Example:
name = "Alice" if name == "Alice": print("Hello, Alice!")
🔑 Key Points:
- Whitespace (indentation) is meaningful
- No semicolons needed at line ends
- Variables don’t need explicit declaration
- Case-sensitive language
- Everything is treated as an object
- Supports both scripting and modular programming
- Beginner-friendly but powerful
1.3 Invoking Python
You can use Python interactively or by writing scripts. It's versatile in how you execute your code, depending on the task at hand.
✅ Interactive Mode (REPL):
$ python >>> print("Hello, Python!") Hello, Python!
✅ Script Mode:
$ python my_script.py
✅ Shebang on UNIX/Linux:
#!/usr/bin/env python3 print("Running with shebang")
🔑 Key Points:
- Use
python
orpython3
to start the interpreter - Run .py files via terminal or IDE
- Use
print()
for output - Quit REPL with
exit()
or Ctrl+D - Can write scripts for automation
- Works in terminal, IDLE, VS Code, PyCharm, Jupyter
- Scripts can be made executable on Linux/macOS
1.4 Basic Principles
Python is guided by design principles that prioritize readability, simplicity, and productivity. It promotes writing clean, logical code for small and large-scale projects alike.
"Simple is better than complex. Readability counts." — The Zen of Python
✅ Example: Exception Handling
try: number = 10 / 0 except ZeroDivisionError: print("You can't divide by zero!")
🔑 Key Principles:
- Minimal Syntax: Less clutter, clean structure
- Modules: Import built-in and external libraries easily
- OOP Support: Full object-oriented capabilities
- Namespaces: Clear variable scopes (LEGB)
- Error Handling: Catch and manage exceptions
- Dynamic Typing: No need to declare types explicitly
- Readability: Pythonic code is self-documenting