Skip to content

How to Escape Python Tutorial Hell and Actually Learn Programming

Problem

When I started learning Python, I thought following tutorials would make me a programmer. I spent hours watching videos and copying code from blog posts, but when I tried to write a simple function on my own, I got this error:

# My attempt after finishing a 3-hour tutorial
def add_numbers(x, y):
result = x + y
return result
# When I tried to use it
print(add_numbers("hello", "world"))
TypeError: can only concatenate str (not "int") to str

I had no idea why this happened. I just copied the syntax from tutorials but didn’t understand how Python actually works.

Environment

  • Python 3.9
  • Ubuntu 20.04
  • Beginner with 2 months of tutorial consumption

What happened?

I was following a Python tutorial that showed how to write functions. The instructor wrote:

def add_numbers(x, y):
return x + y
print(add_numbers(5, 10)) # Output: 15

I copied this exact code and it worked. Then I thought I understood. But when I tried to modify it to add a string, I got that TypeError.

Here’s my setup:

my_functions.py
# I tried to be clever and extend the concept
def add_numbers(x, y):
"""Add two numbers together"""
result = x + y
return result
# I thought this would work
print(add_numbers(5, 10)) # This worked
print(add_numbers("hello", "world")) # This failed
# I tried to understand why
print("5 + 10 =", 5 + 10) # This worked
print("hello + world =", "hello" + "world") # This worked too

I can explain the key parts:

  • The function definition with def
  • The parameters x and y
  • The return statement

But when I tried to understand why add_numbers("hello", "world") failed, I got confused. The error message didn’t tell me what I needed to know.

How to solve it?

I tried reading the Python documentation about type errors:

# I thought I needed type checking
def add_numbers(x, y):
if type(x) != type(y):
raise TypeError("Both arguments must be the same type")
return x + y
# Test it
print(add_numbers(5, 10)) # Works: 15
print(add_numbers("hello", "world")) # Works: helloworld
print(add_numbers(5, "hello")) # Still gives my original error

[Explain why you tried this - brief] I thought the issue was mixing types, so I tried to add type checking.

Then I realized the problem was more fundamental. The tutorial showed me how to use + with numbers, but didn’t explain that + does different things for different types.

So I tried a different approach:

# I focused on understanding what + actually does
def add_numbers(x, y):
"""Add two numbers together, but understand what + means"""
print(f"Adding {x} ({type(x)}) and {y} ({type(y)})")
return x + y
# Test different cases
print(add_numbers(5, 10))
print(add_numbers("hello", "world"))
print(add_numbers([1, 2], [3, 4]))
Adding 5 (<class 'int'>) and 10 (<class 'int'>)
15
Adding hello (<class 'str'>) and world (<class 'str'>)
helloworld
Adding [1, 2] (<class 'list'>) and [3, 4] (<class 'list'>)
[1, 2, 3, 4]

[What changed and why] Instead of trying to fix the “error”, I tried to understand what + actually does for different types. It doesn’t “add” everything in the mathematical sense.

Now I understand the core concept:

# The real solution: understanding operators, not syntax
def add_numbers_or_concatenate(x, y):
"""Better function name that explains what it actually does"""
# Now I know + does concatenation for strings and lists
# and addition for numbers
return x + y
# This works for all types, but does different things
print(add_numbers_or_concatenate(5, 10)) # 15
print(add_numbers_or_concatenate("hello", "world")) # helloworld
print(add_numbers_or_concatenate([1], [2])) # [1, 2]

You can see that I succeeded to understand what operators actually do instead of just memorizing syntax.

The reason

I think the key reason for the error is that I was in tutorial hell. I consumed tutorials passively without understanding concepts. The tutorial showed me this syntax:

def add_numbers(x, y):
return x + y

But it didn’t explain that + is an operator that behaves differently for different types. When I tried to apply this to strings, it didn’t do what I expected because + for strings means concatenation, not mathematical addition.

The real problem is that tutorial hell teaches you syntax without teaching concepts. You can copy code but you can’t explain it or modify it because you don’t understand the underlying principles.

Summary

In this post, I showed how tutorial hell creates programmers who can copy code but can’t write or understand it. The key point is that you need to understand concepts, not just syntax. When you learn something new, immediately test it with different inputs and see what actually happens, not just what the tutorial shows you.

Escape tutorial hell by replacing passive consumption with active experimentation. When you learn about +, test it with strings, lists, numbers, and see what it does for each type. Then you’ll understand why your original code failed and how to write better code.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments