T
18

PSA: Stuck on a basic function for days and it's driving me nuts

Honestly, I picked up Python because everyone says it's easy to start with. Tbh, I watched tons of videos and did the exercises, but when I tried to write a function on my own, I hit a wall. Ngl, the syntax looks simple, but putting it together feels like solving a puzzle blindfolded. I keep getting errors about indentation and missing colons, and the error messages don't make sense to me. It's so annoying because I know what I want the code to do, but I can't make it happen. I even looked up examples online, but they use terms I don't get yet. Now I'm just copying code without understanding, and that feels wrong. Maybe I need to go back to the very basics again.
3 comments

Log in to join the discussion

Log In
3 Comments
the_andrew
the_andrew27d ago
Read a blog post once about Python indentation errors. It said missing colons after function definitions are a common headache. Like, if you write 'def my_function()' without the colon, Python freaks out. Same with mixing tabs and spaces. The error messages can be confusing, but they usually point to the line number. Try using an editor that highlights syntax, it helps catch those mistakes early.
1
jordan_young
Used to skip syntax highlighting until it caught a nasty tabs vs spaces bug for me last week. Now I get why people swear by it.
1
susana66
susana6627d ago
Thought syntax highlighting was just for looks until recently. I always turned it off because I liked plain text. Then I ran into a mix of tabs and spaces in my code. The editor colored them differently, so I saw the problem right away. Fixed it before it caused bigger issues. Now I keep it on all the time because it actually helps avoid mistakes.
2