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

First Steps with Python

Your First Python Program

Every programmer's journey begins with the classic "Hello, World!" program. Let's start with the simplest Python program you can write:

example:

print("Hello, World!")

When you run this program, it will display:

Hello, World!

The print() function is used to display text on the screen. It's one of the most commonly used functions in Python.


Understanding the Python Console

Python provides an interactive console (also called REPL - Read-Eval-Print Loop) where you can test code immediately. You can access it by typing python or python3 in your terminal.

example:

>>> print("Welcome to Python!")
Welcome to Python!
>>> 2 + 3
5
>>> name = "Sarah"
>>> print(name)
Sarah

The >>> symbols indicate you're in the Python interactive mode. This is perfect for experimenting and learning.


Writing Your First Script

While the console is great for testing, you'll want to save your code in files called scripts. Python files have a .py extension.

Create a file called my_first_script.py:

example:

# My first Python script
print("Welcome to my Python program!")
print("Today is a great day to learn programming.")

# Let's do some basic math
result = 10 + 5
print("10 + 5 equals:", result)

To run this script, save it and use:

python my_first_script.py

Working with Variables

Variables are like containers that store data. In Python, creating variables is straightforward:

example:

# Storing different types of information
student_name = "Emily"
student_age = 20
student_grade = 85.5
is_enrolled = True

print("Student Name:", student_name)
print("Age:", student_age)
print("Grade:", student_grade)
print("Enrolled:", is_enrolled)

Notice how we don't need to specify what type of data each variable holds - Python figures it out automatically!


Basic Data Types

Python has several built-in data types. Let's explore the most common ones:

example:

# Numbers
temperature = 23        # Integer (whole number)
price = 19.99          # Float (decimal number)

# Text
message = "Hello there!"    # String (text)
letter = 'A'               # Also a string (single character)

# True/False values
is_sunny = True        # Boolean
is_raining = False     # Boolean

# Let's check their types
print(type(temperature))  # <class 'int'>
print(type(price))        # <class 'float'>
print(type(message))      # <class 'str'>
print(type(is_sunny))     # <class 'bool'>

Getting Input from Users

Making your programs interactive is exciting! Use the input() function to get information from users:

example:

# Getting user information
name = input("What's your name? ")
age = input("How old are you? ")

print("Nice to meet you,", name)
print("You are", age, "years old.")

Important note: The input() function always returns text (string), even if the user types numbers.

example:

# Converting input to numbers
age_text = input("Enter your age: ")
age_number = int(age_text)  # Convert to integer

print("Next year you'll be", age_number + 1, "years old!")

Simple Calculations

Python excels at mathematical operations. Let's create a simple calculator:

example:

# Basic math operations
num1 = 15
num2 = 4

addition = num1 + num2        # 19
subtraction = num1 - num2     # 11
multiplication = num1 * num2  # 60
division = num1 / num2        # 3.75
floor_division = num1 // num2 # 3 (whole number division)
remainder = num1 % num2       # 3 (remainder after division)
power = num1 ** 2             # 225 (15 squared)

print("Addition:", addition)
print("Subtraction:", subtraction)
print("Multiplication:", multiplication)
print("Division:", division)
print("Floor Division:", floor_division)
print("Remainder:", remainder)
print("Power:", power)

Working with Strings

Strings (text) are fundamental in programming. Here are some basic string operations:

example:

first_name = "John"
last_name = "Smith"

# Combining strings (concatenation)
full_name = first_name + " " + last_name
print("Full name:", full_name)

# String length
print("Name length:", len(full_name))

# Making strings uppercase and lowercase
print("Uppercase:", full_name.upper())
print("Lowercase:", full_name.lower())

# Using f-strings (modern way to format strings)
age = 25
message = f"Hello, my name is {full_name} and I'm {age} years old."
print(message)

Creating Your First Interactive Program

Let's combine everything we've learned to create a simple interactive program:

example:

# Personal Information Collector
print("=== Welcome to the Personal Info Collector ===")
print()

# Get user information
name = input("Enter your full name: ")
age = input("Enter your age: ")
city = input("Enter your city: ")
hobby = input("Enter your favorite hobby: ")

# Convert age to number for calculation
age_number = int(age)
birth_year = 2025 - age_number

# Display the collected information
print("\n=== Your Information ===")
print(f"Name: {name}")
print(f"Age: {age} years old")
print(f"Birth Year: {birth_year}")
print(f"City: {city}")
print(f"Favorite Hobby: {hobby}")
print(f"Fun Fact: In 10 years, you'll be {age_number + 10} years old!")

print("\nThank you for using our program!")

Common Beginner Mistakes to Avoid

  1. Forgetting quotes around strings:
# Wrong
name = John  # This will cause an error

# Correct
name = "John"
  1. Mixing up variable names:
# Be careful with spelling
student_name = "Alice"
print(studnet_name)  # Typo! This will cause an error
  1. Not converting input when needed:
# This won't work as expected
age = input("Enter age: ")
next_year = age + 1  # Error! Can't add number to string

# Correct way
age = int(input("Enter age: "))
next_year = age + 1

Practice Exercises

Try these exercises to reinforce what you've learned:

Exercise 1: Simple Calculator

# Create a program that asks for two numbers and displays their sum, difference, and product
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

# Your code here...

Exercise 2: Temperature Converter

# Convert Celsius to Fahrenheit
# Formula: F = (C × 9/5) + 32
celsius = float(input("Enter temperature in Celsius: "))

# Your code here...

Exercise 3: Personal Story Generator

# Create a mad-libs style story using user input
name = input("Enter a name: ")
adjective = input("Enter an adjective: ")
animal = input("Enter an animal: ")

# Create and print a fun story using these variables

What's Next?

Congratulations! You've taken your first steps in Python programming. You now know how to:

  • Write and run Python programs
  • Work with variables and different data types
  • Get input from users
  • Perform basic calculations
  • Work with strings
  • Create simple interactive programs

In the next lessons, you'll learn about:
- Variables and Data Types (in more detail)
- Control Flow (making decisions with if/else)
- Loops (repeating actions)
- Data Structures (lists, dictionaries, etc.)

Keep practicing these basics - they form the foundation for everything else in Python programming!


Quick Reference

Essential Functions:
- print() - Display output
- input() - Get user input
- type() - Check data type
- int() - Convert to integer
- float() - Convert to decimal number
- str() - Convert to string
- len() - Get length of string

Basic Operators:
- + Addition
- - Subtraction
- * Multiplication
- / Division
- // Floor division
- % Remainder
- ** Power