11
Just realized I could debug with print statements after 3 weeks of struggling
I was about 3 weeks into learning Python and hitting a wall with this loop that just would not work. Overheard my buddy's kid who's in high school say 'just print everything' on a call. I tried printing my variables step by step and spotted my typo in like 10 minutes. Has anyone else had that moment where the simplest fix was staring you right in the face?
3 comments
Log in to join the discussion
Log In3 Comments
owens.anthony1d ago
Not gonna lie @the_tessa I think you're overcomplicating it a bit. Yeah sure dump everything to the console isn't smart but for a beginner just getting SOMETHING on screen is the whole point. I read this article once about how beginners learn best by making mistakes visible not by being told the right way first. That first "print everything" win is like a rite of passage. After you've done it a few times you naturally start getting more targeted with your prints. The real lesson is that printing stuff out is faster than staring at code hoping the bug will just jump out at you.
3
juliarodriguez1d ago
Wait, @owens.anthony, 200 lines of output THAT told you nothing? That sounds brutal, I would've given up after like 50 lines and taken a nap. But okay yeah, labeling makes sense, I just feel like beginners need that messy win first to even care about being clean later.
5
the_tessa1d ago
Oh I definitely had a similar moment but honestly the "print everything" method is kind of the wrong way to think about it. You should be targeting specific variables not just dumping everything to the console. I wasted a whole afternoon once printing out every single variable in a function and ended up with 200 lines of output that told me nothing. The trick is to print JUST the thing you're unsure about and label it clearly. Like "print('x after loop:', x)" instead of just "print(x)". That little change saved me SO much time later.
1