Free Online Code Editor
A clear order for learning Python from zero, the topics you can safely ignore for now, and the mistakes that trip up almost every beginner.
Most people don't quit Python because it's too hard. They quit because they try to learn everything at once, hit a wall of unfamiliar words, and decide programming just isn't for them.
It doesn't have to go like that. Python is a good first language, but only if you learn it in a sensible order. This guide gives you that order, tells you what to leave for later, and points out the mistakes that catch nearly everyone.
Python reads a lot like plain English. You don't need semicolons or curly braces to get started, and a "hello world" program is one line. You can also run it right here in the browser with the CompileZ Python editor, so there's nothing to install before you write your first line.
It's also useful in the real world. People use Python for automation, data analysis, web back ends, and machine learning. Whatever you end up building, there's probably a Python library for it.
To be fair, it isn't perfect. Python is slower than languages like C++ or Rust, it isn't the usual choice for phone apps, and its dynamic typing means some mistakes only show up when the program runs. None of that matters while you're learning. It starts to matter much later.
Learn these in sequence. Each step builds on the one before it.
1. Printing and variables. A variable is just a name for a value.
name = "Sam"
age = 29
print("Hello,", name)
print("Next year you'll be", age + 1)Hello, Sam
Next year you'll be 302. Basic types. Numbers, text (strings), and True/False values. Notice that "5" and 5 are different things.
3. Decisions. Use if, elif, and else to make your code choose a path.
temperature = 12
if temperature > 25:
print("Shorts weather")
elif temperature > 10:
print("Bring a jacket")
else:
print("Wear a proper coat")Bring a jacket4. Loops. Use for to repeat something for each item, and while to repeat until something changes.
for day in ["Mon", "Tue", "Wed"]:
print("Today is", day)Today is Mon
Today is Tue
Today is Wed5. Functions. A function packages a few lines of code under a name so you can reuse it.
def add_tax(price, rate=0.13):
return round(price * (1 + rate), 2)
print(add_tax(20))
print(add_tax(20, rate=0.05))22.6
21.06. Lists and dictionaries. A list holds things in order. A dictionary holds things by name. Between them, they cover most of the data you'll handle for a long time.
7. Reading error messages. This is a skill, and it's worth practicing on purpose. More on that below.
8. Small projects. Nothing teaches like building something tiny and slightly useful.
Here's a small program that uses almost everything above. It counts how often each word appears in a sentence and prints the top three.
text = "the quick brown fox jumps over the lazy dog the end"
counts = {}
for word in text.split():
counts[word] = counts.get(word, 0) + 1
top_three = sorted(counts.items(), key=lambda pair: pair[1], reverse=True)[:3]
for word, n in top_three:
print(word, n)the 3
quick 1
brown 1Don't just read it. Paste it into the editor, change the sentence, and break it on purpose to see what happens.
You'll see these topics mentioned everywhere. They're real and useful, but they can wait:
async and awaitIf you're stuck on a topic for more than a day or two, it's usually because you skipped something earlier. Go back a step. That's normal.
Mixing up text and numbers. Anything typed in as text stays text until you convert it.
age = "30"
print(age + 5)TypeError: can only concatenate str (not "int") to strThe fix is int(age) + 5. Quotes make something a string, even if it looks like a number.
Using = when you meant ==. One equals sign assigns a value. Two compare values.
Forgetting the colon or the indentation. Python uses indentation to know which lines belong inside an if, for, or def. Keep it consistent, four spaces per level.
Naming a variable after a built-in. If you write list = [1, 2, 3], you've just hidden Python's own list() function. Names like sum, max, str, and input are all traps.
Look at the last line of the traceback first. That's the actual problem: the error type and a short description. Then look just above it for the line number. Most errors are a typo, a missing colon, or a name spelled two different ways.
Read it out loud. It sounds silly, but it works. "NameError: name 'totl' is not defined" is Python telling you that you typed totl and probably meant total.
if statements. Write ten tiny programs.Thirty minutes a day beats a five-hour weekend session. Short, frequent practice is what makes it stick.
Reading helps, but typing the code is what makes it stick. Open the editor, paste any example from this article, and change it until it breaks.
Open the Python editorLearn how Python list comprehensions work, with filtering, nested loops, dict and set versions, and clear rules for when a plain loop is the better choice.
Understand Python decorators by building a timer, a logger, a retry wrapper, and a cache, with the functools.wraps detail most tutorials skip.
See how Python generators and the yield keyword let you handle huge files and endless streams one item at a time, with clear examples and common gotchas.