Master Python Programming
From Newbie to Professional
Build Your Programming Career
Authored by William H. Simmons
Founder of A Few Bad Newbies LLC
Python Professional Development Course
Module 1: Python Basics
Chapter 1: Introduction to Python
Python is a high-level, interpreted programming language known for its simplicity and readability. It’s widely used for web development, data analysis, artificial intelligence, and more.
# Simple Python program
print("Hello, World!")
Common Mistakes
- Forgetting colons after block statements (if, for, etc.)
- Inconsistent indentation
- Misspelling keywords or functions
Practice printing your name:
print("Your Name")
Chapter 2: Variables and Data Types
Python supports various data types:
# Integer
age = 25
# Float
price = 19.99
# String
name = "Alice"
# Boolean
is_student = True
Pro Tip
Python is dynamically typed, so you don’t declare variable types.
Practice assigning a variable:
name = "Your Name"
print(name)
Chapter 3: Basic Operations
Python supports arithmetic and comparison operations:
# Arithmetic
sum = 5 + 3
product = 4 * 6
# Comparison
is_equal = (5 == 5)
Common Mistakes
- Using = instead of == for comparison
- Mixing incompatible types
Practice an operation:
a = 10
b = 5
print(a + b)
Module 2: Control Flow
Chapter 1: Conditional Statements
Use if, elif, and else for conditional logic:
age = 18
if age < 13:
print("Child")
elif age < 18:
print("Teenager")
else:
print("Adult")
Common Mistakes
- Forgetting colons after conditionals
- Incorrect indentation
Practice a conditional:
score = 85
if score >= 80:
print("Pass")
Chapter 2: Loops
Python supports for and while loops:
# For loop
for i in range(5):
print(i)
# While loop
count = 0
while count < 5:
print(count)
count += 1
Pro Tip
Use range() for easy iteration in for loops.
Practice a loop:
for i in range(3):
print("Loop")
Chapter 3: Loop Control
Use break, continue, and pass to control loops:
for i in range(10):
if i == 5:
break
print(i)
Common Mistakes
- Creating infinite while loops
- Not updating loop variables
Practice loop control:
for i in range(5):
if i == 2:
continue
print(i)
Module 3: Functions
Chapter 1: Defining Functions
Define functions with the def keyword:
def greet(name):
print(f"Hello, {name}!")
greet("Alice")
Common Mistakes
- Forgetting parentheses when calling functions
- Incorrect indentation
Practice defining a function:
def hello():
print("Hi!")
hello()
Chapter 2: Return Values
Functions can return values:
def square(n):
return n * n
print(square(4))
Pro Tip
Return values allow functions to be reusable.
Practice a return function:
def double(x):
return x * 2
print(double(5))
Chapter 3: Default and Keyword Arguments
Functions can have default and keyword arguments:
def greet(name, msg="Hello"):
print(f"{msg}, {name}!")
greet("Bob", msg="Hi")
Common Mistakes
- Default arguments after non-default
- Incorrect keyword argument syntax
Practice a default argument:
def welcome(name, msg="Welcome"):
print(f"{msg}, {name}!")
welcome("Alice")
Module 4: Data Structures
Chapter 1: Lists
Lists are mutable, ordered collections:
fruits = ["apple", "banana"]
fruits.append("cherry")
print(fruits)
Common Mistakes
- Index out of range errors
- Modifying lists during iteration
Practice list operations:
numbers = [1, 2]
numbers.append(3)
print(numbers)
Chapter 2: Tuples
Tuples are immutable, ordered collections:
point = (1, 2)
print(point[0])
Pro Tip
Use tuples for fixed data to prevent changes.
Practice tuple access:
coords = (5, 10)
print(coords[1])
Chapter 3: Dictionaries
Dictionaries store key-value pairs:
person = {"name": "Alice", "age": 25}
print(person["name"])
Common Mistakes
- Accessing non-existent keys
- Using mutable keys
Practice dictionary access:
data = {"key": "value"}
print(data["key"])
Chapter 4: Sets
Sets store unique, unordered items:
nums = {1, 2, 2}
print(nums)
Pro Tip
Sets are great for removing duplicates.
Practice set creation:
items = {"a", "b", "b"}
print(items)
Module 5: Object-Oriented Programming
Chapter 1: Classes and Objects
Classes define objects:
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
print("Woof!")
dog = Dog("Buddy")
dog.bark()
Common Mistakes
- Omitting self in methods
- Not initializing attributes
Practice a class:
class Car:
def __init__(self, model):
self.model = model
def drive(self):
print("Vroom!")
car = Car("Toyota")
car.drive()
Chapter 2: Inheritance
Inheritance allows code reuse:
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
pass
class Cat(Animal):
def speak(self):
print("Meow")
cat = Cat("Whiskers")
cat.speak()
Pro Tip
Inherit to extend functionality.
Practice inheritance:
class Vehicle:
def move(self):
print("Moving")
class Bike(Vehicle):
def move(self):
print("Pedaling")
bike = Bike()
bike.move()
Chapter 3: Special Methods
Special methods customize behavior:
class Point:
def __init__(self, x):
self.x = x
def __str__(self):
return f"Point({self.x})"
p = Point(5)
print(p)
Common Mistakes
- Incorrect dunder method syntax
- Wrong return types
Practice a special method:
class Item:
def __init__(self, name):
self.name = name
def __str__(self):
return self.name
item = Item("Book")
print(item)
Module 6: Error Handling
Chapter 1: Understanding Errors
Common Python errors include:
- SyntaxError: Invalid syntax
- NameError: Undefined variable
- ZeroDivisionError: Divide by zero
x = 10 / 0 # ZeroDivisionError
Common Mistakes
- Ignoring errors
- Typographical errors in variable names
Chapter 2: Try-Except Blocks
Handle errors with try-except:
try:
x = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero")
Pro Tip
Use specific exceptions for clarity.
Practice error handling:
try:
num = int("abc")
except ValueError:
print("Invalid number")
Chapter 3: Raising Errors
Raise custom errors with raise:
age = 5
if age < 10:
raise ValueError("Age too low")
Common Mistakes
- Vague error messages
- Not catching raised errors
Practice raising an error:
value = -1
if value < 0:
raise ValueError("Negative value")
Module 7: Strings and String Methods
Chapter 1: String Basics
Strings are immutable character sequences:
text = "Python"
print(text[0:2])
Common Mistakes
- Attempting to modify strings
- Invalid slice indices
Practice string slicing:
word = "Code"
print(word[0:2])
Chapter 2: String Methods
Common string methods include upper() and strip():
text = " hello "
print(text.strip().upper())
Pro Tip
Chain string methods for efficiency.
Practice a string method:
text = "python"
print(text.capitalize())
Chapter 3: String Formatting
Use f-strings for formatting:
name = "Alice"
print(f"Hi, {name}!")
Common Mistakes
- Misplacing f-string braces
- Using outdated formatting
Practice formatting:
age = 25
print(f"Age: {age}")
Module 8: Modules and Packages
Chapter 1: Importing Modules
Import standard library modules:
import math
print(math.sqrt(16))
Common Mistakes
- Importing non-existent modules
- Incorrect module names
Practice importing:
import math
print(math.pi)
Chapter 2: Random Module
Use random for randomization:
import random
print(random.randint(1, 10))
Pro Tip
Use random.choice() for lists.
Practice random:
import random
print(random.choice(["a", "b"]))
Chapter 3: Installing Packages
Install packages with pip:
# Command line
pip install requests
Common Mistakes
- Incorrect pip commands
- Version conflicts
Note: External package installation not supported here.
Module 9: Advanced Python Concepts
Chapter 1: List Comprehensions
Create lists concisely:
squares = [x**2 for x in range(5)]
print(squares)
Common Mistakes
- Incorrect comprehension syntax
- Overcomplicating comprehensions
Practice a comprehension:
evens = [x for x in range(10) if x % 2 == 0]
print(evens)
Chapter 2: Generators
Generators yield values one at a time:
def count(n):
i = 0
while i < n:
yield i
i += 1
for x in count(3):
print(x)
Pro Tip
Generators are memory-efficient for large data.
Practice a generator:
def nums(n):
for i in range(n):
yield i
for x in nums(3):
print(x)
Chapter 3: Decorators
Decorators wrap functions:
def deco(func):
def wrapper():
print("Start")
func()
return wrapper
@deco
def say():
print("Hello")
say()
Common Mistakes
- Not returning the wrapper
- Forgetting to call func
Practice a decorator:
def log(func):
def wrapper():
print("Log")
func()
return wrapper
@log
def test():
print("Test")
test()
Module 10: Python Projects and Careers
Chapter 1: Planning a Project
Effective project planning:
- Goals: Define the purpose
- Steps: Break into tasks
- Tools: Choose modules
Pro Tip
Use flowcharts for project logic.
Chapter 2: Building a Simple Game
Create a guessing game:
import random
num = random.randint(1, 5)
guess = int(input("Guess: "))
if guess == num:
print("Correct!")
Common Mistakes
- Not converting input to int
- Missing import random
Practice a simple program:
num = 5
if int(input("Enter: ")) == num:
print("Match!")
Chapter 3: Version Control with Git
Track changes with Git:
# Terminal commands
git add .
git commit -m "Update"
Common Mistakes
- Vague commit messages
- Pushing sensitive data
Chapter 4: Python Career Paths
Career options with Python:
- Data Scientist: Analyze data
- Web Developer: Use Django/Flask
- AI Engineer: Build models
Pro Tip
Showcase projects on GitHub.
Python Career Paths
Complete all modules and pass the final test!