Module 1 - Introduction to Python & Setup
This module lays the foundation of Python programming. Before writing any code, you must understand what Python is, why it's popular, where it's used, and how to set up your development environment.
1. What is Python?
Python is a high-level, interpreted, general-purpose programming language created by Guido van Rossum in 1991.
Python emphasizes code readability and simplicity. The language follows the Zen of Python principle: "There should be one—and preferably only one—obvious way to do it."
Key Characteristics of Python
- Simple and easy-to-learn syntax
- Interpreted (no compilation required)
- Dynamically typed
- Object-oriented and functional programming support
- Extensive standard library
- Large ecosystem of third-party packages
- Cross-platform compatibility
Python Use Cases
- Web Development – Django, Flask, FastAPI
- Data Science & AI – Pandas, NumPy, TensorFlow, PyTorch
- Automation & Scripting – Task automation, DevOps
- Backend Development – REST APIs, microservices
- Scientific Computing – Research, simulations
- Testing & QA – pytest, Selenium
Python consistently ranks as one of the most in-demand programming languages globally. It's the language of choice for AI/ML, data science, and rapid application development.
2. Python 2 vs Python 3
Python 2 reached end-of-life on January 1, 2020. All modern development uses Python 3.
Key Differences
| Feature | Python 2 | Python 3 |
|---|---|---|
print "Hello" | print("Hello") | |
| Division | 5/2 = 2 | 5/2 = 2.5 |
| Unicode | ASCII default | Unicode default |
| Status | Deprecated | Active |
Only learn Python 3. Python 2 is no longer maintained and should not be used for new projects.
3. Installing Python
3.1 Official Installation
Windows:
- Download from python.org
- Run installer
- ✅ Check "Add Python to PATH"
- Verify:
python --version
macOS:
# Using Homebrew
brew install python3
# Verify
python3 --version
Linux (Ubuntu/Debian):
sudo apt update
sudo apt install python3 python3-pip
python3 --version
3.2 Using Anaconda (Recommended for Data Science)
Anaconda includes Python + scientific libraries pre-installed.
# Download from anaconda.com
# Verify
conda --version
python --version
4. Python Development Environment
4.1 Interactive Python (REPL)
python3
>>> print("Hello, Python!")
Hello, Python!
>>> 2 + 2
4
>>> exit()
REPL (Read-Eval-Print Loop) is excellent for quick testing and learning.
4.2 Code Editors & IDEs
VS Code (Recommended for Beginners)
- Free and lightweight
- Python extension available
- Excellent debugging support
- Integrated terminal
PyCharm (Professional IDE)
- Best-in-class Python IDE
- Advanced refactoring
- Database tools
- Community Edition is free
Jupyter Notebook (Data Science)
- Interactive notebooks
- Perfect for data analysis
- Inline visualizations
- Browser-based
Other Options
- Sublime Text
- Atom
- Vim/Neovim
- Google Colab (cloud-based)
5. Setting Up VS Code for Python
Installation Steps
-
Install VS Code from code.visualstudio.com
-
Install Python Extension
- Open Extensions (Ctrl+Shift+X)
- Search "Python"
- Install official Microsoft Python extension
-
Configure Python Interpreter
- Press
Ctrl+Shift+P - Type "Python: Select Interpreter"
- Choose your Python installation
- Press
-
Create Your First File
# hello.py
print("Hello, Python!") -
Run Your Code
- Press
F5or - Right-click → Run Python File
- Press
6. Package Management with pip
pip is Python's package installer.
Basic pip Commands
# Install a package
pip install requests
# Install specific version
pip install requests==2.28.0
# Upgrade a package
pip install --upgrade requests
# Uninstall
pip uninstall requests
# List installed packages
pip list
# Show package details
pip show requests
# Install from requirements file
pip install -r requirements.txt
Creating requirements.txt
# Export current packages
pip freeze > requirements.txt
# Content example:
# requests==2.28.0
# flask==2.3.0
# numpy==1.24.0
Always use virtual environments to isolate project dependencies (covered in Module 3).
7. Your First Python Program
hello.py
"""
My First Python Program
Author: Your Name
Date: 2026-01-18
"""
# This is a single-line comment
def main():
"""Main function"""
name = input("Enter your name: ")
print(f"Hello, {name}! Welcome to Python.")
# Basic calculation
age = int(input("Enter your age: "))
print(f"In 10 years, you will be {age + 10} years old.")
if __name__ == "__main__":
main()
Key Concepts Introduced
- Comments:
#for single-line - Docstrings:
"""..."""for documentation - Functions:
def function_name(): - Input:
input()function - Output:
print()function - F-strings:
f"text {variable}" - Type conversion:
int(),str(),float()
8. Python Coding Style (PEP 8)
PEP 8 is Python's official style guide.
Essential Rules
# Good: 4 spaces indentation
def calculate_sum(a, b):
result = a + b
return result
# Bad: Inconsistent spacing
def calculate_sum(a,b):
result=a+b
return result
# Good: Descriptive names
user_name = "John"
total_price = 100
# Bad: Cryptic names
un = "John"
tp = 100
# Good: 2 blank lines before top-level functions
def function_one():
pass
def function_two():
pass
Naming Conventions
| Type | Convention | Example |
|---|---|---|
| Variables | snake_case | user_name |
| Functions | snake_case | calculate_total() |
| Classes | PascalCase | UserAccount |
| Constants | UPPER_CASE | MAX_SIZE |
| Modules | lowercase | utilities.py |
Use tools like black or autopep8 to automatically format your code.
pip install black
black your_file.py
9. Understanding Python Execution
Interpreted Language
Source Code (.py) → Python Interpreter → Bytecode (.pyc) → Python Virtual Machine → Output
Advantages
- No compilation step
- Platform-independent
- Rapid development
- Easy debugging
Disadvantages
- Slower than compiled languages (C, C++, Rust)
- Not suitable for system programming
- Runtime errors instead of compile-time
For performance-critical code, use libraries written in C (NumPy, Pandas) or tools like PyPy, Cython, or Numba.
10. Python Standard Library
Python's strength lies in its "batteries included" philosophy.
Essential Built-in Modules
import os # Operating system interface
import sys # System-specific parameters
import datetime # Date and time handling
import json # JSON encoding/decoding
import math # Mathematical functions
import random # Random number generation
import re # Regular expressions
import pathlib # Object-oriented filesystem paths
Quick Examples
import datetime
import random
import json
# Current date and time
now = datetime.datetime.now()
print(f"Current time: {now}")
# Random number
number = random.randint(1, 100)
print(f"Random number: {number}")
# JSON handling
data = {"name": "John", "age": 30}
json_string = json.dumps(data)
print(json_string)
Summary
✅ Python is a versatile, beginner-friendly language
✅ Always use Python 3 (not Python 2)
✅ VS Code + Python extension is excellent for beginners
✅ pip manages packages and dependencies
✅ Follow PEP 8 style guidelines
✅ Python's standard library is extensive
Next Steps
In Module 2, you'll learn:
- Python syntax fundamentals
- Variables and data types
- Basic operators
- Input/output operations
- Type conversions
Practice Exercises
- Install Python 3 and verify with
python --version - Set up VS Code with the Python extension
- Write a program that asks for your name and age, then prints a personalized message
- Install three packages using pip:
requests,pandas,flask - Create a
requirements.txtfile for your project
Write a program that:
- Asks the user for two numbers
- Performs addition, subtraction, multiplication, and division
- Displays all results in a formatted way