Advertisement

Learn Python for Beginners: Complete Mini Course

Python is probably the best programming language to start with. It's simple, readable, and you can do almost anything with it - web development, data analysis, automation, AI, you name it. I've taught Python to dozens of beginners, and I can tell you: if you can read English, you can learn Python.

This course will take you from zero to writing your first real programs. No prior experience needed. Just follow along, type the code, and you'll get it.

Why Learn Python?

Python is everywhere. Companies use it, researchers use it, hobbyists use it. It's in high demand, pays well, and it's actually fun to use. Plus, the syntax is so simple that you spend less time fighting with the language and more time building cool stuff.

You can use Python for:

  • Automating boring tasks
  • Web development
  • Data analysis and visualization
  • Machine learning and AI
  • Game development
  • Building APIs and backends

Lesson 1: Installing Python

First, you need Python on your computer. Go to python.org, download the latest version (3.x), and install it. Make sure to check "Add Python to PATH" during installation - this makes your life easier later.

To check if it worked, open Command Prompt (Windows) or Terminal (Mac/Linux) and type:

python --version

If you see a version number, you're good. If you get an error, check out our Python setup guide.

Lesson 2: Your First Program

Let's write your first Python program. Open a text editor (Notepad works, but I recommend VS Code or PyCharm) and type:

print("Hello, World!")

Save it as hello.py. Then open Terminal/Command Prompt, navigate to where you saved it, and run:

python hello.py

You should see "Hello, World!" printed. Congratulations - you just wrote and ran your first Python program!

Lesson 3: Variables and Data Types

Variables store information. In Python, you just assign a value and Python figures out what type it is:

name = "Alice"
age = 25
height = 5.6
is_student = True

print(name)
print(age)
print(height)
print(is_student)

Python has several data types:

  • Strings: Text, like "Hello" or "Python"
  • Integers: Whole numbers, like 5 or 100
  • Floats: Decimal numbers, like 3.14 or 5.6
  • Booleans: True or False

Lesson 4: Working with Strings

Strings are super common. Here's how to work with them:

first_name = "John"
last_name = "Doe"

# Combine strings
full_name = first_name + " " + last_name
print(full_name)

# Format strings (f-strings are the best way)
message = f"Hello, {first_name} {last_name}!"
print(message)

# String methods
text = "hello world"
print(text.upper())  # HELLO WORLD
print(text.lower())  # hello world
print(text.title())  # Hello World

F-strings (the f"..." syntax) are the modern way to format strings. They're clean and easy to read.

Advertisement

Lesson 5: Numbers and Math

Python can do math just like a calculator:

a = 10
b = 3

print(a + b)  # Addition: 13
print(a - b)  # Subtraction: 7
print(a * b)  # Multiplication: 30
print(a / b)  # Division: 3.333...
print(a // b) # Integer division: 3
print(a % b)  # Modulo (remainder): 1
print(a ** b) # Exponentiation: 1000

You can also use variables in calculations:

price = 19.99
quantity = 3
total = price * quantity
print(f"Total: ${total}")

Lesson 6: Getting User Input

Make your programs interactive with input():

name = input("What's your name? ")
print(f"Hello, {name}!")

age = input("How old are you? ")
age = int(age)  # Convert string to integer
print(f"You are {age} years old.")

input() always returns a string, so if you need a number, convert it with int() or float().

Lesson 7: If Statements

Make decisions in your code with if statements:

age = 20

if age >= 18:
    print("You are an adult")
else:
    print("You are a minor")

# Multiple conditions
score = 85
if score >= 90:
    grade = "A"
elif score >= 80:
    grade = "B"
elif score >= 70:
    grade = "C"
else:
    grade = "F"

print(f"Your grade: {grade}")

Notice the indentation - Python uses indentation to show what code belongs to the if statement. This is important - Python cares about spacing.

Lesson 8: Lists

Lists store multiple items. They're super useful:

# Create a list
fruits = ["apple", "banana", "orange"]
print(fruits)

# Access items (starts at 0)
print(fruits[0])  # apple
print(fruits[1])  # banana

# Add items
fruits.append("grape")
print(fruits)

# Remove items
fruits.remove("banana")
print(fruits)

# Loop through a list
for fruit in fruits:
    print(fruit)

Lists are zero-indexed - the first item is at position 0, not 1. This trips up beginners, but you'll get used to it.

Lesson 9: Loops

Loops let you repeat code. Two types: for loops and while loops:

# For loop - repeat a set number of times
for i in range(5):
    print(f"Number: {i}")

# For loop with a list
names = ["Alice", "Bob", "Charlie"]
for name in names:
    print(f"Hello, {name}!")

# While loop - repeat until condition is false
count = 0
while count < 5:
    print(count)
    count += 1  # Same as count = count + 1

range(5) gives you numbers 0 through 4. Use range(1, 6) if you want 1 through 5.

Lesson 10: Functions

Functions let you reuse code. Define them with def:

def greet(name):
    return f"Hello, {name}!"

message = greet("Alice")
print(message)

# Function with multiple parameters
def add_numbers(a, b):
    return a + b

result = add_numbers(5, 3)
print(result)  # 8

Functions make your code organized and reusable. Instead of writing the same code multiple times, write it once in a function and call it whenever you need it.

Your First Real Program

Let's combine everything into a simple program - a number guessing game:

import random

number = random.randint(1, 10)
guesses = 0

print("I'm thinking of a number between 1 and 10. Can you guess it?")

while True:
    guess = int(input("Your guess: "))
    guesses += 1
    
    if guess == number:
        print(f"Correct! You got it in {guesses} guesses!")
        break
    elif guess < number:
        print("Too low!")
    else:
        print("Too high!")

This uses everything we've learned: variables, input, if statements, loops, and the random module. Try it out!

Common Mistakes Beginners Make

  • Forgetting colons: If statements, loops, and functions need colons at the end of the line.
  • Wrong indentation: Python uses indentation to show code blocks. Use 4 spaces (or tabs, but be consistent).
  • String vs number: input() returns strings. Convert to numbers with int() or float().
  • Index errors: Lists start at 0, not 1. my_list[0] is the first item.
  • Not saving files: Make sure to save your .py files before running them.

Pro Tip: When you get an error, read the error message. Python's error messages are actually helpful - they tell you what went wrong and where. Don't just panic - read the error!

What's Next?

You've learned the basics! Now try:

  • Building more complex programs
  • Learning about dictionaries and sets
  • Working with files
  • Using libraries and modules
  • Moving on to intermediate Python

Practice is key. Write code every day, even if it's just small programs. The more you code, the better you'll get.

Common Questions

How long does it take to learn Python?

You can learn the basics in a few weeks if you practice regularly. To get really good? Months or years. But you can start building useful programs pretty quickly.

Do I need to be good at math?

Not really. Basic math helps, but you don't need advanced math for most Python programming. You can learn Python even if you're not great at math.

What should I build to practice?

Start simple: calculators, to-do lists, simple games. Then move to web scrapers, automation scripts, data analysis. Build things that interest you - you'll learn faster that way.

Start Coding Today

Don't just read - write code. Open a text editor, type the examples, run them, modify them, break them, fix them. That's how you learn. Start with the simple examples and work your way up. You've got this!

Advertisement