Course Topics
Introduction Python Overview Setting Up Python Python Syntax Basics First Steps with Python Comparing Python with Other Languages Basics Variables and Data Types Input and Output Type Conversion Comments and Code Readability Naming Conventions Control Flow Conditional Statements Loops in Python Loop Control Mechanisms Nested Control Structures Data Structures Working with Strings Lists Tuples Sets Dictionaries Comprehensions Iterators and Generators Functions Defining and Calling Functions Function Arguments and Parameters Lambda Functions Return Values Recursion Variable Scope in Functions Modules and Packages Importing Modules Built-in Modules Creating Custom Modules Working with Packages Virtual Environments Managing Packages with pip Object-Oriented Programming Classes and Objects Attributes and Methods Constructors and Initializers Inheritance and Polymorphism Encapsulation and Abstraction Class Methods and Static Methods Using super() and Method Resolution File Handling Reading and Writing Text Files File Modes and File Pointers Using Context Managers (with) Working with CSV Files Handling JSON Data Error Handling Types of Errors and Exceptions Try, Except, Finally Blocks Raising Exceptions Built-in vs Custom Exceptions Exception Handling Best Practices Advanced Python Decorators Advanced Generators Context Managers Functional Programming Tools Coroutines and Async Programming Introduction to Metaclasses Memory Management in Python Useful Libraries Math Module Random Module Date and Time Handling Regular Expressions (re) File and OS Operations (os, sys, shutil) Data Structures Enhancements (collections, itertools) Web APIs (requests) Data Analysis Libraries (NumPy, Pandas) Visualization Tools (matplotlib) Database Access SQLite in Python Connecting to MySQL/PostgreSQL Executing SQL Queries Using ORMs (SQLAlchemy Intro) Transactions and Error Handling Web Development Introduction to Web Frameworks Flask Basics (Routing, Templates) Django Overview Handling Forms and Requests Creating REST APIs Working with JSON and HTTP Methods Testing and Debugging Debugging Techniques Using assert and Logging Writing Unit Tests (unittest) Introduction to pytest Handling and Fixing Common Bugs Automation and Scripting Automating File Operations Web Scraping with BeautifulSoup Automating Excel Tasks (openpyxl) Sending Emails with Python Task Scheduling and Timers System Automation with subprocess

Setting Up Python

Setting Up Python

Installing Python

To write and run Python programs, you first need to install Python on your computer. The latest version of Python can be downloaded from the official website:

🔗 https://www.python.org/downloads/

Choose the version that matches your operating system:

  • Windows: Download the .exe installer.
  • macOS: Download the .pkg installer.
  • Linux: Python is usually pre-installed. If not, you can install it using your package manager.

Important: Add Python to PATH

When installing Python on Windows, make sure to check the option:

[✓] Add Python to PATH

This ensures you can run Python from any terminal or command prompt window.


Verifying the Installation

After installation, open your terminal (or command prompt) and type:

python --version

Or, on some systems:

python3 --version

You should see something like:

Python 3.11.7

If you see an error or it says Python is not recognized, it means Python wasn't added to your system path properly.


Running Python Code

There are multiple ways to run Python code:

1. Using the Python Interactive Shell

Open your terminal and type:

python

This opens a live Python environment where you can type and run commands line-by-line.

example:

>>> print("hello")
hello

To exit, type exit() or press Ctrl + Z (Windows) or Ctrl + D (macOS/Linux).

2. Writing Python in a File

You can write code in a file with the .py extension.

example (example.py):

print("This is a file")

Run it using:

python example.py

Choosing an IDE or Code Editor

You can write Python using any text editor, but using an IDE (Integrated Development Environment) makes development much easier.

Here are some popular options:

  • VS Code (Lightweight and powerful)
  • PyCharm (Professional and feature-rich)
  • Thonny (Great for beginners)
  • Jupyter Notebook (Popular in data science)

Recommended for Beginners: VS Code or Thonny

They offer:

  • Syntax highlighting
  • Auto-complete
  • Debugging tools
  • Integrated terminal

example (VS Code):

# my_script.py
name = input("What is your name? ")
print("Welcome,", name)

Run your file directly inside the editor or using the terminal.


Installing Python Packages

Python comes with a tool called pip — it helps you install extra features and libraries written by other developers.

To check if pip is installed:

pip --version

To install a package:

pip install package-name

example:

pip install requests

Then in Python:

import requests

You now have access to that package's features.


Virtual Environments (Intro)

Sometimes you may want to isolate your project’s packages so that they don’t conflict with other projects. That’s where virtual environments come in.

To create one:

python -m venv myenv

To activate it:

  • Windows:

bash myenv\Scripts\activate
* macOS/Linux:

bash source myenv/bin/activate

Now you can install packages without affecting the global environment.

To deactivate:

deactivate

Common Setup Errors (and Fixes)

  • "Python not recognized": Python was not added to PATH. Reinstall and check the box.
  • Permission errors on install: Try adding --user to your pip install command:

bash pip install package-name --user
* Using wrong version: Use python3 instead of python if your system has Python 2 by default.


Summary

Setting up Python is the first step toward building anything with it. Once you’ve installed Python and chosen an editor, you're ready to write code and explore the full power of the language.

From here, we’ll dive into the syntax and structure of Python programs in the next section.