Тёмный

STOP Making These Python Mistakes 

Tech With Tim
Подписаться 1,5 млн
Просмотров 113 тыс.
50% 1

Chances are you have made a mistake while programming, and if you code in Python then you know what a unique programming langauge it is! While it is great that Python is unique and has a lot of great features, that also means that there are many ways that you can make mistakes while programming, and may not even realize it! So in this video I am going to walk you through common mistakes and help you follow steps to correct them. I hope you enjoy!
💻 ProgrammingExpert is the best platform to learn how to code and become a software engineer as fast as possible! Check it out here: programmingexpert.io/tim and use code "tim" for a discount!
📄 Resources 📄
Collections Tutorial (Deque, Queue): • Intermediate Python Tu...
Why You Shouldn't Use The Global Keyword: • Why You Shouldn't Use ...
⭐️ Timestamps ⭐️
00:00 | Python Mistakes
00:53 | Mistake #0 - ProgrammingExpert
01:11 | Mistake #1 - Name Shadowing
03:38 | Mistake #2 - Mutable Default Parameters
05:34 | Mistake #3 - Modifying While Iterating
08:05 | Mistake #4 - Name Clashing
09:27 | Mistake #5 - Naked Except
12:13 | Mistake #6 - Wrong Data Structure
16:11 | Mistake #7 - Global Variables
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
👕 Merchandise: teespring.com/stores/tech-wit...
📸 Instagram: / tech_with_tim
📱 Twitter: / techwithtimm
⭐ Discord: / discord
📝 LinkedIn: / tim-ruscica-82631b179
🌎 Website: techwithtim.net
📂 GitHub: github.com/techwithtim
🔊 Podcast: anchor.fm/tech-with-tim
🎬 My RU-vid Gear: www.techwithtim.net/gear/
💵 One-Time Donations: www.paypal.com/donate?hosted_...
💰 Patreon: / techwithtim
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
⭐️ Tags ⭐️
-Tech With Tim
-Programming Mistakes
-Coding Mistakes
-Biggest Coding Mistakes
-Python Mistakes
-Biggest Python Mistakes
⭐️ Hashtags ⭐️
#TechWithTim #CodingMistakes #Python

Опубликовано:

 

13 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 144   
@troyke
@troyke Год назад
Tim, as someone who has vision problems, I REALLY appreciate how you zoom the code in your IDE, so that it's easier to read! It's just ONE of the many reasons your channel is so successful! THANK YOU!
@kamilherbetko5670
@kamilherbetko5670 2 года назад
9:27 is also dangerous because bare except catches BaseException objects, so it will also catch KeyboardInterruptException. This can lead to a program that can only be stopped by killing the process.
@kiranreddy4046
@kiranreddy4046 2 года назад
In the past everything used to fly over my head in these kinds of videos but I’m proud that i can understand and comprehend why these errors can happen while coding and I’ve faced a few scenarios that are mentioned in the video. Great stuff
@tarunreddy7
@tarunreddy7 2 года назад
Same feeling, bro!
@kosmonautofficial296
@kosmonautofficial296 2 года назад
dude same here this stuff is starting to make more sense
@williamreive2101
@williamreive2101 5 месяцев назад
Same!
@BaconBitsJuice
@BaconBitsJuice 2 года назад
Ty Tim. My wife's bf has been giving me more computer privledges lately and your content has really been helping me learn a new skill!
@excalizan7697
@excalizan7697 2 года назад
Wtf
@user-bm7yg3ov1g
@user-bm7yg3ov1g 2 года назад
@@excalizan7697 ikr
@capybarapens
@capybarapens Год назад
lmao my dude mine too ×D
@shreyanshughosh7241
@shreyanshughosh7241 2 года назад
I joined this channel when it have just 250k subs. From that it had a growth of 948k till date. This is just Tim's hardwork n patience which led his success. Wishing all the very best for the future buddy :) Well, thanx for this video too.
@TechWithTim
@TechWithTim 2 года назад
Thank you :)
@Robnoxious77
@Robnoxious77 2 года назад
when modifying iterables (like deleting elements selectively for example), sometimes i’ll iterate through the list backwards, so that the length of the list after a delete (in the direction i’m iterating) doesn’t actually change.
@sarahalzaher7474
@sarahalzaher7474 2 года назад
Smart
@DrDeuteron
@DrDeuteron Год назад
@@sarahalzaher7474 no, clever.
@vicb0
@vicb0 2 года назад
7:50 Instead of creating an aux array or something to store the new list while iterating, you can just iterate a slice of the list which will create a copy for count, value in enumerate(list[:])
@blackdereker4023
@blackdereker4023 2 года назад
List slice will not just iterate over the slice, it will create a copy of the list. Enumerate is a generator and won't create a copy, it will just iterate over the already created list.
@vicb0
@vicb0 2 года назад
@@blackdereker4023 yes, I know. It's exactly what I said
@suche_cz
@suche_cz 2 года назад
creating copy of that list may be inefficient
@jgtb0pl
@jgtb0pl 2 года назад
you can also use filter
@sugumarprabhakaran
@sugumarprabhakaran 2 года назад
Very nice video. This is exactly the type of content that I need since I'm an intermediate-ish programmer and just want to keep getting better. No benefit in going through basics over and over for people stuck at my level. Thank you Tim!
@mgtan8900
@mgtan8900 2 года назад
Hey Tim, good stuff as always. Thanks for the advise. May I know do you have any tutorials on Tkinter to build GUI? I love to learn from you.
@amirilifee
@amirilifee 2 года назад
Thanks much for helping)) Keep it up✊✊✊
@usamashami11
@usamashami11 2 года назад
Insightful! You are inspiring!
@carmelomarasco4746
@carmelomarasco4746 Год назад
Yours is one of the best youtube channel about python. Topics covered are interesting and your explanation is crystal clear. Last, but not the least: I'm not an english native speaker, but I can understand what you says without any effort, your accent and pronunciation are very clear. Thank You
@Lunolux
@Lunolux 2 года назад
great video, learning many think about python again, thx
@akira_asahi
@akira_asahi Год назад
Thank you for the video. I am grateful for your time and contribution. Kind regards, Akira.
@imaginecloudsxo7987
@imaginecloudsxo7987 2 года назад
Hey Tim, could you maybe make a video on Argparse and how to create Subparsers and how you could use them in the command line interface? We just had an assignment with Argparse and I am not quite sure if I actually understand what I am doing when working with Argparse. Thanks in advance!!
@0xtz_
@0xtz_ 2 года назад
U can check the docs it's very simple and anyone can understand it 👍
@TechCowboy
@TechCowboy 2 года назад
@@0xtz_ If she's asking the question, then not everyone can understand it. If you're not going to help her, don't commment.
@miguelguthridge
@miguelguthridge 2 года назад
I'd also love to see this one - argparse isn't exactly the simplest thing ever, and although documentation exists for it, reading documentation can be very difficult, especially for people with ADHD and other attention span disorders.
@chfalcao
@chfalcao 8 месяцев назад
I've been programming since 1984 (yes I'm a dinosaur) and progressed on the corporate ladder up to Senior Management but keep programming as a hobby over weekends. Started learning python 5 years ago and this is the first time I finally understood WHY there's a difference between lists and sets. A pay donation is coming your way after this comment. Keep on the good work.
@TheDuerden
@TheDuerden 2 года назад
I believe you can create a tuple of exception errors - rather than writing a block for each of them, and then use e as you described to provide which one of them was caught. Useful if you don't want long code.
@gabriellopezmontesinos2951
@gabriellopezmontesinos2951 2 года назад
Maybe it's been said already in the comments, but I recommend using the try - except like this: try: blabla except Exception as e: print(e) That way you will directly print the error that is found at the try
@JGnLAU8OAWF6
@JGnLAU8OAWF6 Год назад
Even better is to do: try: ... except Exception: logging.exception()
@anjaan480
@anjaan480 2 года назад
Whats the extension you use to show the errors inline where it occurs?
@Dbrano3
@Dbrano3 2 года назад
Another one, is using the print function instead of the logging function for debugging and general logging of information
@jti107
@jti107 2 года назад
i bought the programming expert course couple weeks ago and just finished it. i recommend it to for new programmers and experienced programmers new to python. you can find similar material on youtube for free but the site organization, the section quizzes/programming exercises and gamification really makes it worth it. there is also a section on Go programming language which I havent done but looks interesting.
@user-xv7so3kw8u
@user-xv7so3kw8u 2 года назад
thanks for useful tips.
@aikimark1955
@aikimark1955 2 года назад
My rule of thumb on changing lists during iteration is to iterate the list from the end to the beginning.
@indiraparajuli9715
@indiraparajuli9715 2 года назад
Tim brother always on 🔥🔥. while Everyday: Quality content++;
@BlyatifulButter
@BlyatifulButter 2 года назад
At mistake #5, if you don't know what kind of exception you'll get, just write "except Exception as e:" and then print out the exception like this: print(f"An exception occurred: {str(e)}") notice the str(e) to convert the error message into a string
@Bruh-sp2bj
@Bruh-sp2bj 2 года назад
This is a terrible thing to do which I dont fault since the people who watch tim are mostly inexperienced coders. Printing out e gives you the __str__() of the exception it doesnt actually contain the full traceback. The error printed is basically useless since it doesnt contain debug information like line number errors or which file the error originates from. It may not even tell you what error was caught since it only passes out the string raised in the exception which may not contain the actual exception name. A better method is to use the traceback stdlib module
@BlyatifulButter
@BlyatifulButter 2 года назад
@@Bruh-sp2bj yeah, that method definitely works way better but I rarely use it in my projects (because I would just remove the try except block to see the full error anyway, I'm stupid), I only preprogram what to do if it caught a certain exception and just print out the rest for me to fix later on.
@JayTailor45
@JayTailor45 9 месяцев назад
Thanks Tim!
@empmachine
@empmachine 5 месяцев назад
Just FYI (since I liked the vid and felt you might care to know), some cultures see an asymmetrical mouth/cheek pull (like if you use your mouth muscles to pull one side of your mouth towards your ear) as a gesture of contempt.
@machineteacher3573
@machineteacher3573 2 года назад
Tim I love you so much and I watch your videos everyday and I'm very excited for you to reach 1m subs. I wanted to suggest that you upload serieses of video for one topic (playlist) because when learning how to code people tend to get attracted to playlists because they are rich of information and demonstrative.
@TechWithTim
@TechWithTim 2 года назад
Great idea! I have a bunch but will definitely consider making more
@pravachanpatra4012
@pravachanpatra4012 2 года назад
Hey Tim can you make Django social media clone or chat app. Or a program in Pygame that can encrypt images or sound?
@TechWithTim
@TechWithTim 2 года назад
I have many!
@seanmackenziedataengineering
@seanmackenziedataengineering 2 года назад
Cool video! These are great points. Usually, if I _have_ to do #3, I will typically iterate backward through the list. Then you can pop anytime and it doesn't affect the outcome.
@quitchiboo
@quitchiboo 2 года назад
Pretty clever.
@DrDeuteron
@DrDeuteron Год назад
@@quitchiboo right, and 'clever' is not a compliment in python.
@quitchiboo
@quitchiboo Год назад
@@DrDeuteron You'll have to elaborate.
@DrDeuteron
@DrDeuteron Год назад
@@quitchiboo clever is unpythonic, as it affects readability: >>>import this
@quitchiboo
@quitchiboo Год назад
@@DrDeuteron Kind of a very broad, unspecific statement. I get what you're saying though. Now given this particular example, readability is not at all impaired, it uses a built-in and avoids a problem quite efficiently, wouldn't that be very pythonic?
@tomasreyestellez485
@tomasreyestellez485 Год назад
Excelent, your resume of common mistakes for new Python users
@CarlFritz24
@CarlFritz24 Год назад
Is there a LIST to avoid those mistakes, Tim ? Also a LIST of built-in Functions would be appreciated.
@Betabdullah
@Betabdullah 2 года назад
Thanks for your videos
@harinivadarevu770
@harinivadarevu770 Год назад
very useful one for python developers !
@michaelmeux4137
@michaelmeux4137 2 года назад
The raw input for some reason doesn't make sense to me. Currently in online school learning code but the course relies on googling to teach the students which is extremely frustrating. Do you have any information or sample code to read through? The primary program we're using is JES and trying to find anything for example without paying for it is difficult.
@Pcoxproductions
@Pcoxproductions 2 года назад
Is there a vs code extension that annotates the time operation of your code like GIT lens?
@davidconiglio7577
@davidconiglio7577 Год назад
Tim ,I am confused. Try to type what codes are made and get lots of mistakes ,try deleting, and can not .how do I get line numbers ?
@PoojaDutt
@PoojaDutt 2 года назад
I really want to start using Python soon .. I’m just dreading the indentation aspect 😅 but I’ve heard it can be a very powerful language. Thanks for this video!
@SACHINYadav-ms2ck
@SACHINYadav-ms2ck 2 года назад
Lets learn together
@ViktorHilmer
@ViktorHilmer 2 года назад
@@SACHINYadav-ms2ck my man is down bad
@BaconBitsJuice
@BaconBitsJuice 2 года назад
@@ViktorHilmer lmao
@chagsssss
@chagsssss 2 года назад
Don't worry about the indentation part, I have been doing Python for 4 months and it hasn't been a problem.
@miguelguthridge
@miguelguthridge 2 года назад
In most programming languages you'll be indenting things anyway (or at least if you aren't then that's awful code style) - most of my students have no problems with Python's indentation for that reason.
@q.w.e.r.t.y
@q.w.e.r.t.y 2 года назад
13:48 So, why is searching through a set faster than searching through a list? Is it just because sets allow no duplicates? If so, then does than mean not having duplicates makes it the same search speed. Or is it to do with the searching algorithm used?
@deadendjesenice
@deadendjesenice 2 года назад
To search a list, you have to loop through all of the values. Best case scenario it is the first element and it's really fast, worst case scenario it's the last element or it doesn't exist. Don't know for certain but a python set is probably implemented using a hastable so it does the lookup in constant time, regardless of the number of elements you want to search. So as the number of elements grows the slower it is to search it. It is also true the other way, if you are interested in for example only two elements, then searching a list would be faster, because the searching algorithm is far less complex. But unless you need those microseconds (the speed of a human eye blink is 100 to 400 milliseconds) the choice for looking a data structure that is used to be tested if an element is a part of should be the set, and you use a list to hold data, which you will then usually loop over it and do something with each element
@imtiazahmad7826
@imtiazahmad7826 2 года назад
I use backward elimination for 6:51
@Mark-zi6nt
@Mark-zi6nt 2 года назад
Non-video related question. If i wanted to stream my pc screen that's working at home to another pc or mobile device, how would i do that? I don't want to constantly get behind my pc and it would my life easier if i was able to monitor stuff and control it via just my phone.
@imranaliss857
@imranaliss857 2 года назад
use Teamviewer
@pieter5466
@pieter5466 Год назад
7:47 do you describe examples of such a list modification anywhere?
@manishbhatia44
@manishbhatia44 Год назад
Hi Tim - im an experienced developer, paused at 3:41 will watch the rest of the video, but for the FIRST mistake - it would be good to give direction to viewers how to correct it. The way I do it and think is one of the ways to avoid name shadowing is to add a. "underscore" before the builtin function your shadowing.... So fix is to do something like this "id" --> "_id"
@Talwyn_Wize
@Talwyn_Wize 2 года назад
I often hear the warning about using a global variable, but not what alternatives to use. Being a complete beginner, I've been stuck on that a few times. Any experiences to share?
@chrysos
@chrysos 2 года назад
v = 3 def do(x): return x+2 v = do(v) # Conclusion: # v was modified without using global (v is now 5)
@piggy3595
@piggy3595 2 года назад
@@chrysos What about if you have a data structure that each method needs to alter? "Don't use global variables" sounds like a dumb "trick" because global variables are needed...
@DrDeuteron
@DrDeuteron Год назад
@@piggy3595 the only thing a method should modify are attributes of the class/instance to which it belongs. So put the data structure in the class and have at it.
@piggy3595
@piggy3595 Год назад
@@DrDeuteron right, so how can multiple methods affect the same variable? global variables
@AddisChess16985
@AddisChess16985 2 года назад
Nice video!
@RomaRapoport
@RomaRapoport 2 года назад
a naked except is really case dependent from my experience and logic dependent
@ABMA79
@ABMA79 2 года назад
I have a question... do you have a series of lessons about python and how to use each feature? You seem like an expert in python and it would be great to learn from someone with such great understanding. Please try to provide a series of lessons in python boosted with examples for illustration purposes.
@TechWithTim
@TechWithTim 2 года назад
I do! But you can also learn everything you need from programmingexpert.io ;)
@ABMA79
@ABMA79 2 года назад
@@TechWithTim Thanks for the reply.
@sarahz2255
@sarahz2255 2 года назад
Hi Tim, I am interested in your course but have a quick question , I have 0 coding experience , if I finished your course will I be job ready ? Thank you
@TechWithTim
@TechWithTim 2 года назад
Yes! You will be at a junior software engineering level
@sarahz2255
@sarahz2255 2 года назад
@@TechWithTim thank you for your reply !:D
@chfalcao
@chfalcao 8 месяцев назад
Thanks!
@TechWithTim
@TechWithTim 8 месяцев назад
Thanks so much!!
@theambassadorstrail
@theambassadorstrail Год назад
I love the tips
@luiselsen7486
@luiselsen7486 2 года назад
I was actually surprised i didn't make these errors the only one i make is using global for easy tkinter programs where i don't give a shit about how it's written
@Iron770
@Iron770 2 года назад
I've run into mutable default parameters before.... Now i know!
@tomgreg2008
@tomgreg2008 2 года назад
good vid, thanks
@jacko314
@jacko314 2 года назад
aren't set and dict O(log(n))?
@karlbooklover
@karlbooklover 2 года назад
I catch exceptions like this, let's you catch them all and print them out except Exception as ex: print(ex)
@Wallee580
@Wallee580 2 года назад
Hiya Tim! I have conflicting feelings with that last one as it is useful to use global variables when dealing with threading or multiprocessing. Here is some quick code I made up for you as an example of what I would think is a global variable done correctly # Import thread from threading using multiprocessing does not seem to work well from threading import Thread # Import system from os from os import system # Define a function to wait for the user to press enter def waitForInput(): # Call the global variable run global run # Ask for input input() # Set run to False run = False # Return return # Define run as Truee run = True # Setup the wait process wait = Thread(target=waitForInput) # Start the wait process wait.start() # Repeat forever while True: # Do some very important stuffs/calculations print("\033[7;37;40mSubscribe to Tech With Tim :p\033[0;37;40m") # Use a break method to prevent an extra print, this uses more time each loop though if run == False: break # Close the wait process wait.join() # Clear the screen system("cls") # Use clear for Linux Okay that was a bit more than a few lines but that is because I tend to comment stuffs for beginners to have an easier time to read. Tell me if there is a way to make this not use a global variable and I will be a very happy programmer :p Thanks for reading, mataatode :')
@NishantCosmos
@NishantCosmos 2 года назад
5:10 why not just if lst: pass
@xzax-mverse7430
@xzax-mverse7430 Год назад
Good info, I found the data structure information to be useful. I've got to say I was a bit annoyed in the name shadowing when you revealed "id" to be a built-in function and therefore a problem under this subject. I thought to myself, "be patient maybe there is a good explanation". So, I looked up the method. I'm still a bit annoyed they decided to use such a common and useful parameter name as a built-in function... If everything is an object with an id it seems much more logical to just leave it within the structure of [object].system_id. Zero need for a built-in function at the global system level. It's a small thing but a bit annoying, certainly not your fault. If there is an argument for this the global method should at least be called get_id() to conform with standards. Further this is where it seems the culture of only "snake_case" comes to bite because the language could easily differentiate global functions with "ProperCase" (GetId()) and then there wouldn't be naming collisions with parameters at all. Makes you wonder about how all this was really decided and if there shouldn't be an offshoot. When I see this, I feel like a lot of stubborn people were involved in the making of this language's norms(scientists and programmers perhaps lol). I'm sure I'm preaching to the choir, but this video posting is where I am right now, so I'm not going to go find the standards committee to make a formal change request lol. So far Python seems like a modern language with some really old hang-ups it needs to shed. I'm trying to keep my mind pried open though even still.
@dovahkiinvokul9073
@dovahkiinvokul9073 2 года назад
8:20 lol this happened to me today, like just 2 hours ago
@nosharing-sf2mk
@nosharing-sf2mk Год назад
these are insane vids
@Th3BlackLotus
@Th3BlackLotus 2 года назад
One dumb mistake I make all the time is asking for input and then not making the corresponding "if input == x" statement match it. Like if I do: xyz = input () If input == 1 Instead of doing: xyz = int(input())
@carlosvazquez2710
@carlosvazquez2710 Год назад
Nice video
@aicode2304
@aicode2304 2 года назад
I don't know if anyone else has the same problem, but I'm currently learning oop, and it feels like everything i do with oop, I'm just copying procedural programming. And I've heard the quote, "the best function is the function with no parameters" but i use a ton of parameters because i don't know what else to do with them. I hope this isn't too confusing.
@Bruh-sp2bj
@Bruh-sp2bj 2 года назад
then you dont understand the purpose of OOP. Pick the right design paradigm for your projects.
@aicode2304
@aicode2304 2 года назад
@@Bruh-sp2bj so not all projects should have oop?
@piggy3595
@piggy3595 2 года назад
@@aicode2304 I mean in java for example, your methods can alter global variables/static variables using the "this" keyword. But functions need parameters. I'm not sure what that quote means contextually, but a function has to take in a parameter otherwise it doesn't have any variable to do anything with (unless function is part of a class, in which case it can use the "this" keyword). Perhaps an example of a function you think needs less parameters could help?
@Bruh-sp2bj
@Bruh-sp2bj 2 года назад
@@aicode2304 obviously. There exist so many paradigms out there OOP shouldnt always be the first thing you use sometimes its not even a good one
@DrDeuteron
@DrDeuteron Год назад
I think all functions should be pure: the result is always the same for the same input, so a parameterless function is useless. Many beginners' OOP is just a script in a class. Tips to avoid that: > A class has one reason to change (see: SRP) > don't do work in dunder init (it's very tempting. Replace with a classmethod helper that does the work and then returns the instance) > make the entire instance in dunder init (pass in all parameters once, no setting later). > only modify instance attributes in its own class methods > avoid functions (on your classes): A class should provide all the methods its instances need. > a method should do one thing (or farm out sub tasks to lesser methods)....e.g., don't have a: def do_all(self):....
@tecart3280
@tecart3280 2 года назад
At mistake 2 i tried running this code and it lead to the same behavior class h: def __init__(self): self.val = 0 def f(g=h()): g.val+=1 return g.val print(f()) print(f()) I think Reference type default parameters does not get created every time
@blackdereker4023
@blackdereker4023 2 года назад
You're right. The class will instantiate once when the function is defined.
@DrDeuteron
@DrDeuteron Год назад
the mistake here is making and instance attribute, 'val', that can't be instantiated. Default to a class attribute and automatically create and instance attribute when accesed. (though f is a sin for modifying an instance variable outside an "h" method) >>> class h: ... val = 0 ... >>> def f(g=h()): ... g.val+=1 ... return g.val ... >>> f() 1 >>> f() 2 >>> f() 3 >>> h.val 0 >>>
@saurabhmahra4084
@saurabhmahra4084 Год назад
So I had an interview for a job in a company, and they forced me to admit that it is a bug that lists in Python gets mutated. Thank god I did not join the company.
@helissonoliveira3807
@helissonoliveira3807 2 года назад
5:23 instead of using lst=None, we could make def mul..(lst=[]): lst_aux = lst.copy() ...
@landsgevaer
@landsgevaer 2 года назад
Works in principle, but way too error prone because you still have access to the mutable empty list. People forget why the copy is there, so stick with an *immutable* sentinel value like None, (or zero, if need be, or similar). You cannot accidentally overwrite or modify a None.
@mohiuddinsyed1684
@mohiuddinsyed1684 2 года назад
Make a tutorial on raylib/pyray Please 🙏🙏🙏. its documentation is very confusing and not as detailed as for Eg: Pygame. And most tutorials out there are for C/C++
@gustavojuantorena
@gustavojuantorena 2 года назад
This video is 🥇🥇🥇
@magicfay
@magicfay 2 года назад
i'm trying to be better but it's been a while since i feel stuck at the beginning
@dziurappa
@dziurappa 2 года назад
You have to code to make mistakes!
@mrolivernone4040
@mrolivernone4040 2 года назад
Lol i've never changed list's length while iterating through it.
@natyacodes
@natyacodes 2 года назад
00:53 is biggest mistake ever made by someone ngl
@baphnie
@baphnie Год назад
Global variables are fine if you know what to look out for. I don't understand why everyone treats them like they're inherently broken.
@rantalbott6963
@rantalbott6963 Год назад
In a way, they are. Python doesn't require that variables be explicitly declared like many languages do. In a language like C, there's no ambiguity about whether a local or global variable is being referenced. In Python, if you don't explicitly declare a variable global, there is. If you have assignments inside if blocks, which variable gets referenced could even vary from one invocation to the next. If you're accustomed to "traditional" compiled languages, that's pretty "broken". Tim has done at least one "Don't use globals" video where he explains how messy this "inheritance" of variables can get. I was shocked by how easy it is for programmers to screw themselves with references to the "wrong" instantiation of variable "x" or "i". It happened to me when I was first learning Python: I had put my "parse command line options" code in a separate function, and declared the option settings globally, as I've customarily done for decades. I got puzzling results until I learned that I needed to declare them as global in the function where I used them. The lack of a requirement for declarations is handy if you're just writing small scripts, but it creates a risk of deploying mistakes that other languages catch and warn you about at compile time.
@baphnie
@baphnie Год назад
@@rantalbott6963 I appreciate you sharing your experience. I’ve been able to assume to date that the behavior is consistent, if not familiar. But I guess that’s not even the case. I’ll keep an eye out for this in my work!
@kassandrarodriguez8057
@kassandrarodriguez8057 2 года назад
I did mistake number 4 one time and I couldn’t figure it out to save my life. My boss had to tell me what I did wrong 😑
@FuShi-hr4vc
@FuShi-hr4vc 10 месяцев назад
the most wrong fail is keep to learn any libriry without learn pygame
@peace-to-the-world
@peace-to-the-world 10 месяцев назад
All built-in functions and reserved keywords MUST be named according to the following rule: {ReservedKeywordName_languageAcronymEnding} Bingo!
@mnageh-bo1mm
@mnageh-bo1mm 2 года назад
What's the Editor Name ??????????????????????????????????????????????????????
@sekiro_19
@sekiro_19 2 года назад
number 2 is poizn
@Damqq
@Damqq 2 года назад
About the "shadow naming" I think this is not completely true that has been spoken... When you define a shadow name you still can access original function definition by calling: __builtins__.foo(), eg: __builtins__.max(), __builtins__.min() or __builtins__.id(). I think this should be adressed :)
@Bruh-sp2bj
@Bruh-sp2bj 2 года назад
no sane programmer does this. Its ugly and unpythonic. Just name your variables properly or prefix them with an underscore
@blackdereker4023
@blackdereker4023 2 года назад
It makes your code less readable.
@Bruh-sp2bj
@Bruh-sp2bj 2 года назад
I respectfully disagree with number 5, there are many valid reasons to use naked excepts and the pitfalls of naked excepts are generally overblown. Typically you want to purposefully catch exceptions before placing general excepts at the end of exception chains. However you can use general excepts for error logging and catching unseen edge cases of well tested programs while not crashing the program in an ungraceful manner. The pitfall of bare excepts can be essentially mitigated with the traceback library that can either print or obtain full traceback messages for logging without actually exiting the program. One thing I will agree on is to not use except on its own this catches anything including KeyboardInterrupt and SystemExit, its better to catch except Exception which allows SystemExit and KeyboardInterrupt calls to properly propagate. I guess the idea I want to bring across is that catching general exceptions is perfectly fine as long as you know what you are doing
@floppitommi123
@floppitommi123 Год назад
you should have posted this a year agooo
@Grempington
@Grempington Год назад
Can safely say in all my years of writing python I never made even a single one of these mistakes, even early on. Source: I have never written anything in python
@illegalsmirf
@illegalsmirf 2 года назад
The biggest mistake is using Python in the first place
@icey1111
@icey1111 2 года назад
first
@santiagoley6403
@santiagoley6403 2 года назад
19 minutes for 7 errors is too much, this should be more concise.
@keewinek
@keewinek 2 года назад
first mistake: You're using python.
@iwakeupsad
@iwakeupsad 2 года назад
Lame comment.
@Mets_xx_Fan_01
@Mets_xx_Fan_01 2 года назад
magic = 200 magic2 = 33 magic3 = 0 def success(dedication, persistence, passion): dedication += 1 # dedicate yourself persistence += 1 # be persistent passion = True # have passion if magic2 > magic: print("this doesn't work") magic = dedication + persistence return magic else: print("Success is near") magic = 0 return magic # Succes is near please help me with this code i don't know how to fix it
@datdwaa1532
@datdwaa1532 2 года назад
for mistake one i never have that problem cuz I name them eeeeeeeeeeeeeee and hi and bonk
Далее
Python's Magical Itertools Module
14:33
Просмотров 78 тыс.
Python's 5 Worst Features
19:44
Просмотров 85 тыс.
СКАЧАЛ РОДИТЕЛЯМ МУЗЫКУ 8
00:47
Просмотров 84 тыс.
How To Actually Make $10k A Month Coding
14:54
Просмотров 78 тыс.
This Is Why Python Data Classes Are Awesome
22:19
Просмотров 790 тыс.
Python 101: Learn the 5 Must-Know Concepts
20:00
Просмотров 1 млн
5 Tips To Organize Python Code
12:16
Просмотров 214 тыс.
What Backend Language is Right For You?
6:55
Просмотров 22 тыс.
The Flaws of Inheritance
10:01
Просмотров 897 тыс.