5 Common Python Mistakes and How to Fix Them




[ad_1]

This video is sponsored by Skillshare. Be one of the first 500 people to sign up with this link and get 2 free months of Skillshare Premium:
https://skl.sh/coreyschafer2

In this Python Programming Tutorial, we will be going over some of the most common mistakes. I get a lot of questions from people every day, and I have seen a lot of people making these same mistakes in their code. So we will investigate each of these common mistakes and also look at the fixes for each other these as well. Here are the timestamps for each topic we will cover…
1) Indentation and Spaces – 0:45
2) Naming Conflicts – 4:12
3) Mutable Default Args – 10:05
4) Exhausting Iterators – 16:35
5) Importing with * – 22:13

PATH Tutorial – https://youtu.be/OdIHeg4jj2c
Iterators Tutorial – https://youtu.be/jTYiNjvnHZY
Generators Tutorial – https://youtu.be/bD05uGo_sVI

✅ Support My Channel Through Patreon:
https://www.patreon.com/coreyms

✅ Become a Channel Member:
https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join

✅ One-Time Contribution Through PayPal:
https://goo.gl/649HFY

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist
http://a.co/inIyro1

✅ Equipment I Use and Books I Recommend:
https://www.amazon.com/shop/coreyschafer

▶️ You Can Find Me On:
My Website – http://coreyms.com/
My Second Channel – https://www.youtube.com/c/coreymschafer
Facebook – https://www.facebook.com/CoreyMSchafer
Twitter – https://twitter.com/CoreyMSchafer
Instagram – https://www.instagram.com/coreymschafer/

#Python

Source


[ad_2]

Comment List

  • Corey Schafer
    December 19, 2020

    If my voice sounds a bit off then it's because I'm getting over a cold. I hope everyone finds this overview of these common mistakes useful. To save you time, I put a list of the common mistakes and the timestamps for each in the description of the video. And again, this video was sponsored by Skillshare. If you'd like to check out Skillshare with 2 free months of Skillshare Premium, you can use my link here:
    https://skl.sh/coreyschafer2

  • Corey Schafer
    December 19, 2020

    Thank you very much .This was very helpful to me.

  • Corey Schafer
    December 19, 2020

    I would be the happiest man in the world if you make it a series

  • Corey Schafer
    December 19, 2020

    check my python project 👇👇👇

    https://youtu.be/O4SfWk9Vbns

  • Corey Schafer
    December 19, 2020

    Many thanks

  • Corey Schafer
    December 19, 2020

    Thanks . The tips were quite useful.

  • Corey Schafer
    December 19, 2020

    Great video, but there is a subtle fallacy: in Mutable Default Args at 13:39, Corey says, incorrectly, that you can equivalently write "if not emp_list" instead of "if emp_list is None". With the "if not emp_list", if we feed the add_employee function with an empty list emps, the name will not be appended to emps. Thus, "… is None" and "not …" are not always interchangeable.

  • Corey Schafer
    December 19, 2020

    don't use 'if not emp_list:' that would also be true if you passed an empty list, meaning it would ignore an empty list you passed in, and always create a new one itself which might be surprising

  • Corey Schafer
    December 19, 2020

    Impressive to watch these tips which I'm not aware so long time..especially naming convention potential risks…Thank you !

  • Corey Schafer
    December 19, 2020

    This addresses problems my students commonly have. Very nice.

  • Corey Schafer
    December 19, 2020

    python is frustatung more like C for me

  • Corey Schafer
    December 19, 2020

    Instead of capturing the iterator items in a list, another way to access the items again is to call zip again.

  • Corey Schafer
    December 19, 2020

    Amazing gotchas! Thank you sir!

  • Corey Schafer
    December 19, 2020

    Thank you, very helpful!

  • Corey Schafer
    December 19, 2020

    the basic text editor for python, IDLE, does this by default I believe. I've never actually had this problem

  • Corey Schafer
    December 19, 2020

    it's useful thanks

  • Corey Schafer
    December 19, 2020

    Thanks Corey, your videos have helped me to build clear python foundations. I always get to your channel for clarification and learning! Excellent work

  • Corey Schafer
    December 19, 2020

    haha i ran into that second one, was playing around with the random library, and saved the file as random, thought i broke something was about to uninstall the whole thing until i found this answer.

  • Corey Schafer
    December 19, 2020

    Regarding the emp_list=[], it's run once. But why its value is kept for the next run? This is a variable that is local to the function and should disappear at end of each run of the function.

  • Corey Schafer
    December 19, 2020

    Thank you for your videos Corey! Perfect pace/depth combination. One question on naming variables. Many times I want to create a class or a function, and then assign a variable with the same concept. Example: I create a class dog: and then I would like to create a variable called dog=dog(). Which I cannot obviously do. Is there any good naming convention in such cases? Define the class something like class class_dog: ?

  • Corey Schafer
    December 19, 2020

    Wow, this was amazingly helpful!
    I had no idea about that default args problem…
    And the iterator exhaustion issue seems super helpful for future hair ripping sessions!

  • Corey Schafer
    December 19, 2020

    please help me how to fix badzipfile error using instapy

  • Corey Schafer
    December 19, 2020

    Hi Corey, is there a Numpy playlist in your contents, i couldn't find one in your website and in youtube

  • Corey Schafer
    December 19, 2020

    Dude your channel is fantastic. I've taken two college courses so far where we used python and I always wished the professors would teach us the fundamental tricks of the trade. They didn't. They only taught about the big concepts like Encapsulation, Inheritance, Polymorphism, Algorithms, Data Structures etc.. which is obviously important to learn but I feel like the basics are so critical yet overlooked in the curriculum. Thankfully your channel is available for us to learn. Thanks!

  • Corey Schafer
    December 19, 2020

    You're really helping me out! I am super grateful!

  • Corey Schafer
    December 19, 2020

    Always learn something new from your videos, even stuff I didn't know I wanted..lol. Great videos Corey mate!

  • Corey Schafer
    December 19, 2020

    Good day sir. Do you have any videos on string , bytes, encoding , and decoding?

  • Corey Schafer
    December 19, 2020

    Love the video Corey keep them coming!

  • Corey Schafer
    December 19, 2020

    Love the video Corey keep them coming!

  • Corey Schafer
    December 19, 2020

    Love the video Corey keep them coming!

  • Corey Schafer
    December 19, 2020

    Can you make a video about naming variables – programmer's hardest challenge 😅😂?

  • Corey Schafer
    December 19, 2020

    list comprehension

  • Corey Schafer
    December 19, 2020

    Hey I created a simple turtle screen but when the screen pops up is says not responding. Any advice?

  • Corey Schafer
    December 19, 2020

    Hi I am so new to python, I am using "Python Crash course" 2nd edition by Eric Matthes. So I am learning step by step, I followed all instructions to install Python and Sublime text editor. So yes it does start off with Hell World, now when I did this for my very first time everything worked, and it worked a couple more times, then I took the next step of adding the variable and that is where I messed things up. I went back traced my steps but I could not get it to work. I took the final step of completely uninstalling Python and Sublime and reinstalling it. Problem is when the reinstall is complete and I open Sublime it still shows the old code , I was hoping that wiping everything out would clear the history as well but it did not.

    Now I am using windows 10 home edition, with a system type of 64-bits OS and X^$-base processor, and it is all running on a HP laptop . Now asking where I went wrong would be just silly, but I would like to know how to fix this or find out where things took a wrong turn.
    Reason I am learning python just because…

  • Corey Schafer
    December 19, 2020

    Naming your string as str or a list of things as list is a sure shot way of getting crazy…

  • Corey Schafer
    December 19, 2020

    Hi Corey, please make video on multiple inheritance and common problems associated with it

  • Corey Schafer
    December 19, 2020

    Process " program 1" is running.
    Program 1 is not allowed to run in parallel. Would you like to stop the running the running one?
    Every time when i try to run a code this problem occurs, how can i solve this problem? Please someone help

  • Corey Schafer
    December 19, 2020

    dude thanks I accidently pressed tab and did not realized thanks man

  • Corey Schafer
    December 19, 2020

    Thank you so much!

  • Corey Schafer
    December 19, 2020

    do else if elif common mistakes please

  • Corey Schafer
    December 19, 2020

    Thanks

  • Corey Schafer
    December 19, 2020

    You should cover circular import dependencies in one of your videos. That’s always a good refresher.

  • Corey Schafer
    December 19, 2020

    Wow! I actually have a developer job since 5-6 months and the thing with the default list screwed me up 😂
    Great video, you’re really helping people out!

  • Corey Schafer
    December 19, 2020

    Great tips!!

  • Corey Schafer
    December 19, 2020

    Thanks man, did you do some video about PEP8?

  • Corey Schafer
    December 19, 2020

    I would like to know some channel teaches Java as neat as Corey does here in Python.. 👏👏
    People can suggest your options pls.. 😊😊

  • Corey Schafer
    December 19, 2020

    Thank you for your videos.

    I am about 1 1/2 months new to Python. I saw this video and went back to look at some of the self-learning I've been doing. I found a way, actually, I am sure I copied some code and modified it today to see if it would work. I can't tell you why it works but it works. I guess I better figure out why it works so I can feel confident in coding.

    I am using Pycharm latest version. I am using Python 3.7 on a Windows 10 machine.

    import time

    from datetime import datetime

    def display_time():

    t = time.strftime('%Y-%m-%d (%I:%M:%S %p)')

    print(t)

    time.sleep(1)

    display_time()

    time.sleep(1)

    display_time()

    time.sleep(1)

    display_time()

    My result was the result you got after you fixed it.
    Please, some smart person explain why it works, I don't have the knowledge to do it.

  • Corey Schafer
    December 19, 2020

    Thanks Corey, useful video

  • Corey Schafer
    December 19, 2020

    Learned a bunch! Thanks!

    A question about default arguments. Overuse of NoneType causes a lot of bugs in my team's code. We've insisted in many places to initialize optional args to avoid type switching. I was not aware of the buggy behavior you outlined, but the `if val is None` pattern adds a lot of boilerplate for more complex functions. Do you have any more advanced notes on how to keep my mid-level pythonistas from getting burned?

  • Corey Schafer
    December 19, 2020

    Default arguments was a surprise, good one 👍

Write a comment