Python Course Lecture Notes
Introduction to Python
- Instructor: Mosh
- Python is highly popular for automation, AI, and web development (Instagram, Dropbox)
- Designed for beginners; no prior experience needed
- Course includes core concepts and three Python projects
Projects Overview
- Grocery Store Website
- Built using Django, a popular Python framework
- Homepage displays products and includes an admin area for stock management
- Music Recommendation using Machine Learning
- Predicts music preferences based on user profiles
- Similar to YouTube's video recommendations
- Automation Tool
- Python program processes thousands of spreadsheets quickly
Course Structure
- Designed for all ages and experience levels
- Hands-on exercises to build confidence
- Instructor has 20 years of experience and taught over 3 million people
Setting up Python
- Download and install Python from python.org
- Check latest version (e.g., Python 3.7.2)
- Important: Add Python to PATH during installation (especially for Windows)
- Install code editor: PyCharm
- Professional edition (paid) or Community edition (free)
Writing Your First Python Program
- Create a new project in PyCharm:
- Click
Create New Project
- Set base interpreter to Python 3
- Create a new Python file (e.g.,
app.py
)
- Example Code:
print("I am Mosh Hamedani")
- Run the program and observe output in terminal.
Drawing with Python
- Another example to draw shapes:
print("o ----")
print(" | |")
Learning Python Duration
- Consistent practice (2 hours/day for 3 months) to write basic programs
- Specialization in desired area (web development, AI, etc.)
- Total time to job readiness: 9-12 months
- Expected salary for junior developers: $50-60k
Variables in Python
- Variables are fundamental:
- Define using
name = value
- Types: integers, floats, strings, booleans
- Example:
price = 10
rating = 4.9
name = "Mosh"
User Input
- Use
input()
to receive user input
- Concatenate strings for dynamic messages:
name = input("What is your name?")
print(f'Hi {name}')
Data Types and Lists
- Lists are used to store multiple items:
numbers = [1, 2, 3, 4]
- Access items using index, slice syntax, and methods like
append()
, remove()
, sort()
, count()
, etc.
Functions in Python
- Define functions using
def
keyword:
def greet_user(name):
print(f'Hi {name}')
- Functions can return values:
def square(number):
return number * number
Error Handling
- Use
try
and except
blocks to handle exceptions:
try:
# code that may cause an error
except ValueError:
# handle the error
Classes and Objects
- Define new types using classes:
class Dog:
def bark(self):
print('Woof')
- Use constructor (
__init__
) to initialize attributes.
Inheritance in Classes
- Use inheritance to reuse code in classes:
class Animal:
def walk(self):
print('Walking')
class Dog(Animal):
def bark(self):
print('Woof')
Modules and Packages
- Organize code into modules (files) and packages (folders).
- Import modules using:
import module_name
from module_name import function_name
Built-in Modules
- Python has many built-in modules (e.g.,
random
, math
).
- Use
pip
to install additional packages.
Data Handling with Pandas
- Load CSV data using Pandas:
import pandas as pd
df = pd.read_csv('filename.csv')
- Use DataFrame methods to manipulate data.
Conclusion and Next Steps
- Course provides foundational skills in Python programming.
- Explore complex projects using machine learning, Django, etc.