← Back to videos

How to turn bad code into good: analyzing loops in Python

In this video I'll show you how to gradually improve bad code using the example of choosing a loop in Python while solving a simple task. I'll show what mistakes beginners make: from using incomprehensible single-letter variables to illogical loop structure.

For whom is this video?
• For those just starting to learn Python and who want to write good code from the start.
• For those preparing for a Junior Python Developer interview and who want to review the basics to minimize the risk of a mistake on basic questions.

What to expect:
✅ An example of bad code and its improvement
✅ Why it's important to avoid throwaway and single-letter variables
✅ Basic principles of clean and readable code.
✅ A simple rule for choosing the right loop in Python.

Don't forget to like, subscribe to the channel and write your questions or examples of "bad code" you've encountered in the comments.

Timestamps:

00:00 Introduction
00:49 Problem statement and bad code solution
02:15 Variable naming
04:04 Analyzing the logic of the original solution
04:57 Literals in code
06:09 Throwaway variables
07:00 Reducing expressions
07:23 Error when choosing a loop
10:23 Loop variable
11:07 Getting rid of unnecessary calculations
13:06 Rule for choosing a loop
13:06 When to iterate by indexes
13:06 13:06 Closing words

Links to documentation:
https://wiki.python.org/moin/ForLoop
https://peps.python.org/pep-0008/

#Python #Programming #Learning #Interview #JuniorDeveloper #CleanCode