PLEASE Stop Making These Python Coding Mistakes

Tech With Tim · Beginner ·🔍 RAG & Vector Search ·11mo ago

Key Takeaways

The video discusses common Python coding mistakes, including mutable default parameters, modifying while iterating, shadowing built-ins, decimal precision, not closing files, and not understanding method implications, and provides guidance on how to fix them.

Full Transcript

If you write code in Python, then I'm willing to bet that you've made at least one of the mistakes that I'm going to show you in this video. So, stick around and I'm going to show you what the mistakes are and how you can fix them. All right, so let's dive into it here with the first mistake, which is using mutable default parameters. Now, I've mentioned this in many videos, but it's still extremely common, so I want to go over it again. Now, a parameter is one of the variables that you have as the inputs to your functions or to your methods. Now, you can make an optional parameter. So something like this where you don't need to pass it and you can give it a default value. So in this case something like a list meaning if I don't pass my list it will be equal to this empty list. However the error here occurs when you have something that is the optional parameter value that is mutable. Mutable meaning it can be changed. So in this case a list is mutable. Something like a set is mutable. A dictionary etc. Now I want to show you what happens when we run this example code. You would expect that we're going to get a list that contains one fruit which is apple and one name which is Tim, right? Because when we append without passing the list, it should be an empty list and then we should just get two separate lists here. However, watch when I run this code and see what the output is. And notice that we get the same list twice. So again, you can kind of look at this code and you can see what we're getting, right? We call this append item, we pass apple, we call this append item, we pass Tim. And for some reason, they're actually the exact same list. Now the reason for that is because we have a mutable value here. So what happens the first time when we call append item is this list is already created and we use the reference to this list to append this item which is apple. Now you can imagine this list is actually equal to apple or apple's inside of it. So the next time we call append item with Tim, Tim simply gets inserted inside of this list because this is a mutable value. So this is a big mistake. it can cause a lot of bugs in your program and you never want to do this. So let me show you how we can fix this. Rather than having this mutable value being equal to something like a list, we can actually just make it equal to none. Then inside of our function, we can say if my list is equal to none, then what we can do is we can say my list is equal to a new list. Now, by doing this inside of the function, we end up creating a new list every time the function is called rather than using a reference to the same list that's created when the program is kind of initialized, if that makes sense. I'm not using the exact syntax, the exact correct terms, but I'm just trying to make you understand. So now, if I run this code, you'll see that we fix the problem and we get Apple and we get Tim. Okay? So, make sure you don't use any mutable values inside of your default parameters for functions or methods. Otherwise, you're going to get a problem like this when you're repeatedly calling the function and not passing this default. The next mistake on my list is modifying while iterating. And this is specifically applying to iterable objects. So things like lists for examples, dictionaries, sets, etc. All right. So have a look at this list right here. We have a bunch of names, users. Then what we do is we loop over these users. We check if the user starts with some letter, in this case E, and then if it does, we remove it. Now, this is very common. We do this all the time. We want to modify some kind of iterable object while we iterate over it. However, if you do this directly, so if you actually modify the thing that you're iterating over, you can get some really weird behavior. Now, at first glance, this seems like it's going to work fine. And actually, if I run this, everything's all good. We end up removing Eve. There's no problem. And this code just works properly. However, if we have certain values in our list, so for example, we have something like Ellen here. You'll notice that the code starts to misbehave. So, let me run this now. And notice that Ellen actually stays in our list, even though it definitely starts with an E. And based on this code, we should have removed it. The reason why we didn't remove it is because we're modifying this list while we're iterating over it. So, Python is not able to actually keep track of where we are in the list when we're changing the length of the list, which is what we're doing here by removing users. Now, this happens the same if you're adding elements to the list and pretty much if you're changing the length of it at all. And there's all kinds of other weird things that you can do intentionally or unintentionally here, but the point is you need to be very careful if you're modifying the list while you're iterating over it. Now, let me explain to you why this actually happens. Internally, Python is keeping track of the index it's on while it's iterating through our users. So, imagine there's some invisible variable like index equals zero. Now, the first index is zero, which references Alice. So, we go through here, nothing happens. We go to index one, which is Bob. Same thing, nothing happens. Two, Charlie. Three, Dave. And then finally, four, Eve. Now, at this point, we remove Eve. So when we remove Eve, the length of our list actually changes and it goes from six to five. Now, Python is comparing the index that it's about to go to, which is five, to the length of the list here, and it sees, oh, my index is the same as the length. That means I must have completed iterating through the list because the last index is always going to be one less than the length. So, it just stops and it doesn't execute this next element in the for loop. So in this case, we ended up skipping Ellen and we never actually even checked it in this loop. However, it doesn't just happen in this situation. For example, if I have another Bob or something here in this list, a similar thing is going to happen due to the fact that we're adjusting the length. So let's go here and change this to B. And maybe let's just make this Bellin or something. And we can go beef just so we can see what happens. And let's run this and see that we kind of get this weird example where we have one Bob, we have one Bellon, and anytime we have some kind of duplicate elements beside each other, they end up getting skipped. Okay, so a lot of weird behavior can happen here if you're modifying a list or an iterable while you're going over it. Now, before we dive in further, let me introduce you to today's sponsor, Manage Engine Site 247, a powerful observability platform built for modern hybrid IT environments. Whether you're monitoring on-prem infrastructure, remote offices, or cloudnative networks, site 247 brings everything together into a single unified view with support for routers, switches, firewalls, load balancers, and cloud managed devices like Cisco Mori. It helps you track key metrics like latency, packet loss, and bandwidth usage all in real time. And thanks to intelligent alerting, your team can proactively catch issues before they affect users. But it doesn't stop there. Site 247 also includes tools like network configuration manager to automate config backups and ensure compliance and net flow analyzer to dive deeper into bandwidth trends and traffic patterns. So whether you're managing a few branch offices or a globally distributed hybrid network, site 247 simplifies complexity and delivers actionable insights. So, if you're ready to optimize your network, then click the link in the description to learn more about Site 24/7 and evaluate the product for free. The next mistake I have for you is a super simple one, but this is shadowing built-ins. Now, built-ins are reserved keywords in Python for things like functions, constructors, types, etc. Now, in this case, we've shadowed the built-in type, which is list. So, list is built into Python. Okay? If we use it, it's actually a constructor that can create a list for us. However, if we name something list, so if we create a variable, we say list is equal to something like 1 2 3. This is going to work fine. We can use this as a variable, but it ends up breaking the built-in functionality of Python's list function constructor type, whatever you want to call it. So, if I run this, you'll see like there's no problem. We can print out list. However, if I come down here now and I try to convert something to a list using the list constructor like I might before, you see that we get an error and it says the list object is not callable. So you don't want to do this. You don't want to shadow the built-in type. And it's very common that people do this with things like list, things like dictionary because this is built in as well. Things like set for example. And another one that a lot of people miss is ID. Okay. So all these variables that are built into Python that actually have some functionality. Don't use them as variable names. Don't use them really anywhere inside of your code. And if you want to do something like this, name it something like my list or I commonly go with LST, right? Or rather than dictionary, you can go with DCT or something along those lines. But always just add something to it, even like dicting the built-in name. Now, the next example to show you is one that really got me confused when I first saw this because I was like, why the heck is that the case? But this is decimal precision inside of Python and honestly inside of most programming languages. Now, if you look at these examples right here, you can see that we're adding 0.1 plus 0.2. You would expect that that is going to give us 0.3. Same thing here where we have some total, we're looping 10 times, we're adding 0.1. You would expect that we're going to get one. However, if I save this and run, you can see that we actually get these really long decimal values. Now, the reason why this happens in computer programming in general is because computers are not able to accurately represent decimal points. I'm not going to get into all of the exact details in terms of how this works, but essentially the binary that computers use is not capable of doing extremely precise decimal precision math, at least in languages like Python. So you end up getting these really weird results when you try to do things like add decimal points together, subtract them, multiply them, etc. So you have to be very careful when you're working with decimals in these languages because if you were to do something like 0.1 plus 0.2 to is equal to 0.3. This would actually return false to you. Okay. So, I'm going to show you an alternative approach when you're using decimal values in Python to ensure that you get the correct results. And obviously, if you're building something like a finance program, this would be very very important. There's actually a lot more issues that pop up due to this, but I'm just showing you the basics, you're aware that this is a thing. Okay, so let me just comment out this right here. Actually, let's bring this back here. Okay, so this is a super simple library that's built into Python called decimal. Now, it's intended to fix the problem with precision by allowing you to add decimals and represent them as strings. So, in this case, I have a and b. I've made a decimal. I said, okay, I'm going to have a value of 0.1 and 0.2 and then I can add them together and I actually get 0.3. You also have the ability to represent things as fractions. So if you have really long decimal values that you wouldn't want to type out, for example, you can use this fraction library again built into Python and you can add the fractions properly. So the next mistake is just a silly one, but I wanted to mention it because it happens all the time and that's forgetting to close a file. So a lot of times in Python, you'll open a file. So in this case, we opened a text file. We're maybe reading from it or writing to it or something along those lines, but we forget to write the line f.clo. Now, this is problematic because when you leave the file open, you're exposing what's known as a memory leak. And this can cause some unintended behavior with the file, especially if other processes are modifying it, reading it, etc. So, you just want to make sure that you're always closing the file after you open it. And one way to avoid this is to use something called a context manager, which handles this for you. Now, this is best practice. What I'm about to show you is what you should pretty much always do when you're dealing with files. So, just forget this open syntax and do this instead. So we're going to say with open same thing file.txt open this in whatever mode as you want. We can say as f and then we can do something like f dot in this case has to be read because we're opening it in r mode and then we can do whatever operation that we want. So when we do this we use this width which is known as a context manager. It will automatically handle closing the file for us even if an error occurs inside of this width statement and it just cleans up the file for us automatically. So you can just do any of the operations related to the file inside of this indented block and not worry about closing it, not worrying about handling exception and it's all good to go. So just always use width, whether you're reading, writing, appending, doesn't matter. Width is just the best practice. So now we move on to the last mistake which in my opinion is the most consequential especially if you're looking to become a real professional software engineer. Now, this is not understanding time complexity implications of the Python code that you're writing. Now, Python is a great language because it has so many built-in tools and features that make your life easier. However, you should understand how those work on a lower level so you know when you should use them or not. That's because when we write code, every line of code that we write takes a certain amount of time to execute. We have all these different time complexities that you may have heard before if you've ever looked at data structures and algorithms. For example, something like constant time or bigo of one, which means it just takes pretty much one operation to run. Something like big O of N. This means it's linear time. So if we have a list with, for example, 100 elements, it would take approximately 100 operations in the worst case scenario in order for us to run this operation. There's a bunch of other time complexities. I'm not going to teach you time complexity in this video, but the point is all these lines of code that we write, they cost a certain amount of time. And when we write code, we want to write the most efficient code possible that cost the least amount of time. But unfortunately, in Python, there's all these little methods that you can use that end up costing a lot of time that many people are not aware of. So, let me show you a few examples here so you see what I mean. Okay, so I have this list items, right? It has three elements. 1 2 3. Now for lists specifically and strings as well there's a lot of these methods that you can use. So things like dotinsert dotdelete removefind. Now these are really useful but if you don't know what they're actually doing on the lower level you might be surprised at how inefficient your code can be when you're using them. So when I use I'm inserting element zero at index zero. That's what it means. So I'm inserting this at the front of my items. Now this is fine. This will work. However, this ends up costing me what's known as big O of N time, where N is the length of the list. So essentially, if my list was 1 million elements, it would cost me approximately 1 million operations to actually make this insertion at the beginning of the list. The reason for that is I actually need to push all of the elements that are in my list over one. So I actually have to do this. I have to create this kind of new array. So like 1 2 3 0. I then need to take these elements and I need to move them one by one. So I need to move three here, two here, one here, and then insert zero over here. So I had to touch every single element in my list in order to make this insertion. Now again, that's fine. You can still run this method, but you should know that behind the scenes that's what's happening. I'm going to show you a few other examples as well, but oftent times when you're using these methods, there's actually a better approach that would be significantly faster in order to do this same type of operation. So, for example, in Python, we have something called a deck or a DQ or whatever you want to call it. Double-ended Q is really what it stands for. Now, what we can do is we can import this double-ended Q. And this gives us what's known as constant time insertion and removal because it's a queue that's double-ended, meaning we can insert from the front and the back in constant time. So, if I was going to do 10,000 insertions, for example, then it would be significantly faster for me to use this deck or double-ended queue than it would be for me to use this insert method from kind of raw Python without importing this data structure. Now, I know this is a little bit confusing, especially if you're a beginner in Python. The point is you need to know what's actually happening when you use these methods especially once you start getting more advanced and ask yourself is this really the most efficient way to do this or can I implement some kind of other data structure or approach. Let's move on to the next example so you can see now how this one works. Okay. So here's another one that is very common. Let's say I have this list and I have 1 million elements in it and I'm looking to see if this element exists inside of my values. Now, especially if this element is going to exist near the end of my list, this little innocent looking operation right here where I check if this thing is in this thing actually cost me the entire length of the list. That's because I need to potentially look through every single element that's inside of here to see if this exists inside of the values. Okay? So if I were to do this many times, this would be very very expensive because I have this massive list and I'm constantly looking through all of the values in this list to see if some element exists. Okay. Now, a faster way to do this, especially if you're going to be doing this more than one time using this in operation, is to convert this list into a set. Now, a set is a data structure that allows for constant time insertion, deletion, and lookup. Okay, now it costs us a bit of time to create this set. That's fine. But when we want to check if something exists inside of a set, it's practically instant. So in this case, us checking if this value exists inside of the set is approximately 1 million times faster than if we were to actually use this list. Now, obviously that's a bit of an exaggeration. It's not exactly like that in practice. But the point is the set is significantly faster for doing a lookup. So if you're going to constantly do these types of lookup lookups, sorry, then don't just use this in use the set. Again, you have this really beautiful syntax in Python that looks like it works really well and it does its purpose, but it costs a lot of time. Again, this costs us linear time where this here actually just costs us constant time O of one because of the underlying data structure that we're using. Okay, let's go to the next example, example three, which is also a very common mistake related to strings. Okay, so a string in Python is what's known as a mutable data type. That means that we can't modify it once it's created. So if we want to do something like a string concatenation, which means adding a string to another string, this actually requires us to create an entirely new string. So let me show this to you. If I have a string like hello, okay, and I have a string like exclamation point and I want to add them together. You might think, well, it's as easy as just taking this exclamation point and just squishing it to hello. However, this actually ends up costing us the time of the first string which we can call n and the time of the second string which we can call uh m. Okay, the time complexity of this operation is O of N plus O of M. Again, if you don't know time complexity, it's fine. The point is it's whatever the length of this string is and whatever the length of this string is, that's how much time it costs us to do this concatenation. Now, that's very expensive if we do this over and over and over again. So, if we look at this example here, we have some result. What we're doing is we're looping through 10,000 numbers and we're just adding all of the numbers with a comma into this result string. Now, this shouldn't be something that should cost us a significant amount of time to do, but based on the way that we've written it, it will cost us because we have this string concatenation, which means we're constantly doing this really expensive operation. So, instead of doing that, you can actually do something like this. You can create a list which is mutable which now gives us a property that we didn't have before with strings which were immutable. And rather than constantly doing a string concatenation which is very expensive, we can just add these elements to this list which only cost us constant time o of one time. We can do this practically instantly. Whereas here this cost us the length of the left string plus the length of the right string. Okay? So, we end up adding all of these elements to this list. And then we just do one operation at the very end where we turn this entire list into a big string. This code right here is going to be significantly faster than this code here, even on relatively small inputs. And that's just because of the way that we've written it and our understanding of the data structures and the operations that we're performing in Python. Now, again, I don't want to get too complex here because this is a whole other video that I could make and if you want that video, let me know in the comments down below. The point is understand what these operations are actually doing and the amount of time that they cost to ensure that you're writing more efficient code. All right guys, so with that said, that's going to wrap up the video. If you enjoyed, make sure to leave a like, subscribe to the channel, and I will see you in the next one. [Music]

Original Description

Checkout Manage Engine Site24x7 and eveluate the product for free: https://www.site24x7.com/promo-signup.html?pack=1001&utm_source=TECHWITHTIM-Network&utm_medium=Youtube&utm_campaign=YoutubeInfluencer If you write code in Python, then I'm willing to bet that you've made at least one of the mistakes that I'm going to show you in this video. So stick around and I'm going to show you what the mistakes are and how you can fix them. Want to make real money with coding? I share high-signal insights on careers, monetization, and leverage in my free newsletter. Join here and get my guide How to Make Money With Coding instantly: https://techwithtim.net/newsletter ⏳ Timestamps ⏳ 00:00 | Mutable Default Parameters 02:46 | Modifying While Iterating 07:00 | Shadowing Built-Ins 08:29 | Decimal Precision 10:36 | Not Closing Files 12:02 | Not Understanding Method Implications Hashtags #Python #SoftwareEngineer #CodingTips
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Tech With Tim · Tech With Tim · 0 of 60

← Previous Next →
1 A* Path Finding Algorithm(Visualization)
A* Path Finding Algorithm(Visualization)
Tech With Tim
2 Python Programming Tutorial #1 - Variables and Data Types
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
3 Python Programming Tutorial #2 - Basic Operators and Input
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
4 Python Programming Tutorial #3 - Conditions
Python Programming Tutorial #3 - Conditions
Tech With Tim
5 Python Programming Tutorial #4 - IF/ELIF/ELSE
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
6 Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
7 Python Programming Tutorial #6 - For Loops
Python Programming Tutorial #6 - For Loops
Tech With Tim
8 Python Programming Tutorial #7 - While Loops
Python Programming Tutorial #7 - While Loops
Tech With Tim
9 Python Programming Tutorial #8 - Lists and Tuples
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
10 Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
11 Python Programming Tutorial #10 - String Methods
Python Programming Tutorial #10 - String Methods
Tech With Tim
12 How to Overclock a NVIDIA GPU
How to Overclock a NVIDIA GPU
Tech With Tim
13 Python Programming Tutorial #11 - Slice Operator
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
14 Python Programming Tutorial #12 - Functions
Python Programming Tutorial #12 - Functions
Tech With Tim
15 Python Programming Tutorial #13 - How to Read a Text File
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
16 Python Programming Tutorial #14 - Writing to a Text File
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
17 Python Programming Tutorial #15 - Using .count() and .find()
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
18 Python Programming Tutorial #16 - Introduction to Modular Programming
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
19 Python Programming Tutorial #17 - Optional Parameters
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
20 Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
21 Python Programming Tutorial #19 - Global vs Local Variables
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
22 Python Programming Tutorial #20 - Classes and Objects
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
23 Cool VBS Script to Prank Your Friends!
Cool VBS Script to Prank Your Friends!
Tech With Tim
24 How to Overclock an AMD GPU
How to Overclock an AMD GPU
Tech With Tim
25 Best GPU'S For Mining Ethereum (2018)
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
26 Recursion and Memoization Tutorial Python
Recursion and Memoization Tutorial Python
Tech With Tim
27 Ethereum Mining Rig - Hardware Guide
Ethereum Mining Rig - Hardware Guide
Tech With Tim
28 Pygame Tutorial #1 - Basic Movement and Key Presses
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
29 How to Install Pygame (Windows 8/10)
How to Install Pygame (Windows 8/10)
Tech With Tim
30 How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
31 How to Mine Ethereum 2018 - WORKING (Super-Easy)
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
32 Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
33 Pygame Tutorial #2 - Jumping and Boundaries
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
34 Pygame Tutorial #3 - Character Animation & Sprites
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
35 Pygame Tutorial #4 - Optimization & OOP
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
36 OBS Studio Tutorial - Best OBS Settings
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
37 Linear Search Algorithm - Python Example and Code
Linear Search Algorithm - Python Example and Code
Tech With Tim
38 Make Any Mic Sound AMAZING! (WITH OBS)
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
39 Binary Search Algorithm - Python Example & Code
Binary Search Algorithm - Python Example & Code
Tech With Tim
40 Pygame Tutorial #5 - Projectiles
Pygame Tutorial #5 - Projectiles
Tech With Tim
41 Pygame Game - Mini Golf
Pygame Game - Mini Golf
Tech With Tim
42 Pygame Tutorial - Projectile Motion (Part 1)
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
43 Pygame Tutorial - Projectile Motion (Part 2)
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
44 Pygame Tutorial #6 - Enemies
Pygame Tutorial #6 - Enemies
Tech With Tim
45 Pygame Tutorial #7 - Collision and Hit Boxes
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
46 Pygame Tutorial #8 - Scoring and Health Bars
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
47 Cloud Mining vs. Hardware Mining - 2018
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
48 How to Install Pygame on Mac OSX (Fast-Simple)
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
49 Pygame Tutorial #9 - Sound Effects, Music & More Collision
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
50 Pygame Tutorial #10 - Finishing Touches & Next Steps
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
51 How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
52 How to Create a Button in Pygame [CODE IN DESCRIPTION]
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
53 Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
54 Pygame Side-Scroller Tutorial #2 - Random Object Generation
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
55 Pygame Side-Scroller Tutorial #3 - Collision
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
56 Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
57 How to Create A Message Box in Python - Tkinter
How to Create A Message Box in Python - Tkinter
Tech With Tim
58 Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
59 How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
60 Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim

The video highlights common Python coding mistakes and provides tips on how to avoid them, making it a useful resource for beginner Python programmers.

Key Takeaways
  1. Avoid using mutable default parameters
  2. Be cautious when modifying while iterating
  3. Avoid shadowing built-in functions
  4. Understand decimal precision
  5. Close files after use
  6. Understand method implications
💡 Being aware of common coding mistakes can help Python programmers write better, more efficient, and more readable code.

Related AI Lessons

Why you shouldn’t search your documents directly with AI
Learn why directly searching documents with AI can be inefficient and how retrieval-augmented systems can improve the process
Medium · Programming
Your AI Keeps Making Things Up. RAG Is How You Make It Use Real Facts Instead.
Learn how to use RAG to make your AI provide accurate answers based on real facts instead of making things up
Medium · RAG
Evaluation Metrics for RAG: Measure Retrieval, Generation, and End-to-End Quality With Numbers That…
Learn to evaluate RAG models using metrics that measure retrieval, generation, and end-to-end quality
Medium · AI
Evaluation Metrics for RAG: Measure Retrieval, Generation, and End-to-End Quality With Numbers That…
Learn to evaluate RAG models using metrics that measure retrieval, generation, and end-to-end quality
Medium · Data Science

Chapters (6)

| Mutable Default Parameters
2:46 | Modifying While Iterating
7:00 | Shadowing Built-Ins
8:29 | Decimal Precision
10:36 | Not Closing Files
12:02 | Not Understanding Method Implications
Up next
RRF vs DBSF with Qdrant: Hybrid Retrieval Fusion for RAG in Python
Professor Py: AI Engineering
Watch →