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: skl.sh/coreyschafer2
THANK YOU! I surmised that tabs and spaces don't mix because i'm just starting out with programming and in spite of looking I could not find a definitive anser to this question. It would have saved me a metric ton of headache had you made this video sooner so, FYI, its YOUR fault that my head hurts so much! :) Thanks! :D
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!
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.
Pitfall No. 2 was literally me a couple of weeks ago! :) I tried out a package and _of course_ I named my testing script file after the package itself! Thanks for making this video, I really appreciate your effort. And it shows: this video feels concise but still in-depth; I can easily follow your thoughts and arguments. This is one of the best tutorials videos I have seen so far. This very video is what makes youtube such an amazing place!
Awesome video Corey. I just got the notification and watched it. Your videos are very good. I just shared your channel link to all my colleagues and friends who truly wanted to learn python. Keep up the good work brother. ..!
When I saw this title I was going to suggest mutability understanding/awareness, especially with regards to default values. Bingo, it already made your list. Nice. As a programmer coming from C++ and learning Python later, this was the most important unexpected thing I learned from the Learning Python book (a good book for learning Python from a single book).
Also I've been away from Python for a bit and only lightly used generators so exhausted generators related to changes from Py2 to Py3 was new info for me.
thank you ,been a short sweet ride with your beginner tutorial and already feel like I learned alot ,now time to move to the longer 143 part playlist !
Thanks Corey, your videos have helped me to build clear python foundations. I always get to your channel for clarification and learning! Excellent work
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!
thank u for uploading...i like ur django series....besides ur presentation and voice is so much standard for an ideal lecturer. could u plz upload some video on pygame, threading and multiprocessing.?..a new series may be....
u said that tabs cannot b used for indents but in yr code it says that indentation error was found in line 6 which was the line u used spaces for indentation? 2:20
Thanks corey. I had this problem of saving the file name same as the module in standard library and could not find out what the error is. Thanks again for saving my time
Woow I didn't know about the default argument one. That's bizarre behavior you don't see in other languages...I need to go back and check some things now lol
This is the best resource for improving at Python. PS. Maybe a vid on practice interview questions in Python? Very relevant at the moment (for me haha). Thanks once again!
I have an older video on Python Interview Tips. You can find it by searching my channel. I really would like to make an update video though, because I feel like it's not one of my better videos. I would definitely do it differently if I remade it today. I do plan on making one at some point in the next couple of months though.
@@coreyms Thanks for the reply. I've searched the channel for "Interview questions" I believe, saw that video there yeah, but didn't watch it yet. I was thinking more actual practice questions, but again maybe you have that in the vid. I'm gonna watch that one for now.
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?
Thanks a lot for that setting! I thought tabs were already translated to spaces (at least when writing html and js). Now I don't have to worry about tabs in python neither
I just realized that help actually prints the help messages and doesn't return them as a string because it printed None on 25:50. Good to know. Also, you could have used to "from os import *" and show how reading a file fails because of the clash with os.open. Good video anyways.
Stumbled aboud the second one a while ago, took waay too long to figure out what happened there.. asterisk-import: another example that can happen is if you import sys and os, both have a 'path' member, these two might be found a little more often than glob and html Thanks for the video! :D
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.
One of the problems I faced early on was that I was installing packages using PIP, and then when I would try to import those packages with VS Code it'd tell me that these packages were not installed. After doing some digging I ended up finding that I was installing those packages for an older version of Python (3.6), and trying to compile my code with a 3.7 interrupter. Maybe you should mention this in one of your future videos. I feel like this could be an issue that some people will struggle with for a while.
When a function expects an argument to be a reference to a function and you mistakenly add ()’s to the function name which then calls the function, it can be difficult to find the problem in your code.
the weird thing is that i often use default mutable (kw)arguments exactly for that reason, the "data" stays with the function, but it "remembers" its past runs, by the first part i mean it saves you having to pass a variable around form one function to another wich can be a hasle to do if the function is getting called in multple places but every call needs to be aware of what happened before , the goto way of negotiating this would be to use a global but indeed globals.... and theire problems , one of them being you dontalways think to check for them or remember/find everywhere they are set or changed, but using a mutable (kw)argument is always there with the function definition. (sidenote : i avoid writing classes for stuff that shouldnt be a class or even stuff that can be done without a class like the plague wich wich would be the goto way of OOP-style programmers instead of globals)
Can you explain how to set up an exit function, to exit from a running python3 program from a users input (say shift plus key combination) without raising an error and giving a clean exit? I am thinking about a program running in idle.
@Corey Schafer i followed your sublime 3 steup video and setup as it mention but whenver i run code without any import statement i get error like this /usr/local/bin/python3: can't find '__main__' module in '' please help me to fix
Very helpful, thanks for sharing! I've been using Python for years, mostly v2 and this helps push me to switch 100% to Python v3 so I can curb my old bad habits.
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!
I have one question about the default argument. Why it reset the list to none each time you run the function?it contradicts with what you said that it runs the default argument one and only once.
It is still setting the values to the default value every time, but they are only evaluated once. So if it is set to a value like None then it will get set to None by default if no arguments are provided. But if it's set to an empty list then it will create that new list once, and then it will get set to that same list by default if no arguments are provided. Since lists are mutable, you will be able to see that original list being modified. You won't be able to tell with immutable data types because they can't be modified. I really like this explanation in this StackOverflow answer... I should have incorporated it into the explanation: stackoverflow.com/questions/10676729/why-does-using-arg-none-fix-pythons-mutable-default-argument-issue
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.
Two points that interact in ways that seem quirky till you "get" the Python idiom. The default value is remembered from creation of the function. The default given and remembered is mutable: that means if you change the value you have changed the default. In C terms think of it as the address which at the time of creation points to an empty linked list. If you add to the list the address remains the same but the contents vary. The implentation is not quite the same, but that's the basic idea. That idea is helpful in making the transition from C (at least I found it so) but try to move on as soon as you can to thinking in Python terms: that that's just what mutable objects do: a mutable object can have different values over time.
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
Thanks a lot for the effort you put into your quality videos, your teaching style is awesome but please can you do something on Django e-commerce website?
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.
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
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:
skl.sh/coreyschafer2
Take care sensei !
Kindly make these videos shorter max 15 min. I can assure you more views
THANK YOU! I surmised that tabs and spaces don't mix because i'm just starting out with programming and in spite of looking I could not find a definitive anser to this question. It would have saved me a metric ton of headache had you made this video sooner so, FYI, its YOUR fault that my head hurts so much! :) Thanks! :D
hey your voice is perfect but you increased the speed and it is creating problem
@@richaverma320 I didn't increase the speed. I just naturally talk a bit fast
"Default arguments are only executed once when the function is declared " You made my day, thanks Corey !
Not when the function was declared, but when it was first run/called.
@@nosahama yes, thank you. This makes more sense!
[Edit] Sorry for ressurecting this 1-year old comment.
Yes, it helped me from a lot of trouble!
Thanks Corey!
lol
For mobile users:
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
Mind if I ask you how you did that? I didn't know I could get clickable timestamps on mobile.
@@coreyms They are only clickable in the comment section, the ones in the description don't work 🙃
@@coreyms Besides that they are the same
Ah, interesting. Thanks for the reply! I'll be sure to add description timestamps to my pinned comments from here on out. I appreciate the tip.
@@coreyms I appreciate the content🙃
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!
The truth is that the professors themselves don’t know the tricks
Thanks for all the work you're putting in on these lessons, Corey! I love seeing a TH-cam alert that you've posted a new video.
Thanks Corey. That empty list as default argument lesson is really great. I appreciate it very much.
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.
blasphemy! who sent you infidel?
Pitfall No. 2 was literally me a couple of weeks ago! :) I tried out a package and _of course_ I named my testing script file after the package itself!
Thanks for making this video, I really appreciate your effort. And it shows: this video feels concise but still in-depth; I can easily follow your thoughts and arguments. This is one of the best tutorials videos I have seen so far. This very video is what makes youtube such an amazing place!
Always learn something new from your videos, even stuff I didn't know I wanted..lol. Great videos Corey mate!
That naming conflict issue caused me so much confusion in the past. Nice tips Corey.
Nice, I love it. I'm learning new things in Python all the time. Please keep up these videos. Thanks Corey.
Awesome video Corey. I just got the notification and watched it. Your videos are very good. I just shared your channel link to all my colleagues and friends who truly wanted to learn python. Keep up the good work brother. ..!
Thanks!
When I saw this title I was going to suggest mutability understanding/awareness, especially with regards to default values. Bingo, it already made your list. Nice.
As a programmer coming from C++ and learning Python later, this was the most important unexpected thing I learned from the Learning Python book (a good book for learning Python from a single book).
Also I've been away from Python for a bit and only lightly used generators so exhausted generators related to changes from Py2 to Py3 was new info for me.
thank you ,been a short sweet ride with your beginner tutorial and already feel like I learned alot ,now time to move to the longer 143 part playlist !
You are excellent teacher Corey. Many thanks for crisp and clear information with apt words.
Thanks Corey, your videos have helped me to build clear python foundations. I always get to your channel for clarification and learning! Excellent work
Love the video Corey keep them coming!
Great work - the mutable default argument issue is commonly asked on quizzes
this video you made is one of best to resolving our problems during learning your course
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!
Nice video!!
Continue with this quality.
Thank you!
You should cover circular import dependencies in one of your videos. That’s always a good refresher.
I did notice your voice is different than normal. I was thinking it was my computer's issue. Well, great video again!! Hope you get better soon!!
the best pythonist ever. thank you corey
This cleared up some things for me, thanks so much Corey!
Really useful stuff! Thanks Corey!
Impressive to watch these tips which I'm not aware so long time..especially naming convention potential risks...Thank you !
Yet another Great video. Always learning somthing new. Thanks!
You're really helping me out! I am super grateful!
Great tutorial. Thank you Corey.
Always the best! Thank you Corey!
18:20 I would also say that unzipping in a for loop (for name, hero in identities) doesn't work in Python 2 either
Great tips!!
I love your videos...please keep them coming they are very helpful
thank u for uploading...i like ur django series....besides ur presentation and voice is so much standard for an ideal lecturer. could u plz upload some video on pygame, threading and multiprocessing.?..a new series may be....
u said that tabs cannot b used for indents but in yr code it says that indentation error was found in line 6 which was the line u used spaces for indentation? 2:20
Thanks Corey, useful video
Thanks corey. I had this problem of saving the file name same as the module in standard library and could not find out what the error is. Thanks again for saving my time
I would be the happiest man in the world if you make it a series
Amazing gotchas! Thank you sir!
Thanks . The tips were quite useful.
Thank you, very helpful!
Woow I didn't know about the default argument one. That's bizarre behavior you don't see in other languages...I need to go back and check some things now lol
great tips!
Thank you very much .This was very helpful to me.
This is the best resource for improving at Python.
PS. Maybe a vid on practice interview questions in Python? Very relevant at the moment (for me haha).
Thanks once again!
I have an older video on Python Interview Tips. You can find it by searching my channel. I really would like to make an update video though, because I feel like it's not one of my better videos. I would definitely do it differently if I remade it today. I do plan on making one at some point in the next couple of months though.
@@coreyms Thanks for the reply. I've searched the channel for "Interview questions" I believe, saw that video there yeah, but didn't watch it yet.
I was thinking more actual practice questions, but again maybe you have that in the vid. I'm gonna watch that one for now.
Good day sir. Do you have any videos on string , bytes, encoding , and decoding?
Looks simple but could give a lot of headaches. Thanks for the video.
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?
Thanks a lot for that setting! I thought tabs were already translated to spaces (at least when writing html and js). Now I don't have to worry about tabs in python neither
Naming your string as str or a list of things as list is a sure shot way of getting crazy...
Thanks
I just realized that help actually prints the help messages and doesn't return them as a string because it printed None on 25:50. Good to know.
Also, you could have used to "from os import *" and show how reading a file fails because of the clash with os.open. Good video anyways.
Stumbled aboud the second one a while ago, took waay too long to figure out what happened there..
asterisk-import: another example that can happen is if you import sys and os, both have a 'path' member, these two might be found a little more often than glob and html
Thanks for the video! :D
Thanks for Skillshare. I just signing up to explore the courses :)
Many thanks
Great video! I should watch more of Corey's videos.
Aaaargh, you bastard. I paused the video at the first example and was staring at the code, wondering where the hell the problem was supposed to be! xD
it's useful thanks
Thank you so much!
the list thing was very useful
Thanks man, did you do some video about PEP8?
Hello Corey... Could you please make videos on data structures and algorithms
Hi Corey, please make video on multiple inheritance and common problems associated with it
Hi Corey, is there a Numpy playlist in your contents, i couldn't find one in your website and in youtube
thanks!
14:52 - Wow, that is REALLY annoying. Coming from PHP, this would have driven me mad, and probably still will! Thanks for sharing.
Default arguments was a surprise, good one 👍
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.
You’re not using arguments to your function there, so everything within the function will get run every time the function is run.
@@coreyms is it pythonic to do it the way I did it or is it frowned on?
I would like to know some channel teaches Java as neat as Corey does here in Python.. 👏👏
People can suggest your options pls.. 😊😊
Java venamey ✌️
@@Venkatyful enakku venumey sago.. just for carrier shift but a short term need.
One of the problems I faced early on was that I was installing packages using PIP, and then when I would try to import those packages with VS Code it'd tell me that these packages were not installed. After doing some digging I ended up finding that I was installing those packages for an older version of Python (3.6), and trying to compile my code with a 3.7 interrupter. Maybe you should mention this in one of your future videos. I feel like this could be an issue that some people will struggle with for a while.
Hey there. Good point. I have done a video on that topic “PATH issues”. But you’re right, it would be good to have pointed that out a bit more
Corey Schafer oh my apologies. I didn’t know that there was already a video on this topic. Thank you I’ll give it a watch!
When a function expects an argument to be a reference to a function and you mistakenly add ()’s to the function name which then calls the function, it can be difficult to find the problem in your code.
Hey Dude.!! Can u please help to sort a list in an ascending order ..with taking two loops...
the weird thing is that i often use default mutable (kw)arguments exactly for that reason, the "data" stays with the function, but it "remembers" its past runs, by the first part i mean it saves you having to pass a variable around form one function to another wich can be a hasle to do if the function is getting called in multple places but every call needs to be aware of what happened before , the goto way of negotiating this would be to use a global but indeed globals.... and theire problems , one of them being you dontalways think to check for them or remember/find everywhere they are set or changed, but using a mutable (kw)argument is always there with the function definition. (sidenote : i avoid writing classes for stuff that shouldnt be a class or even stuff that can be done without a class like the plague wich wich would be the goto way of OOP-style programmers instead of globals)
thank you :)
Hey I created a simple turtle screen but when the screen pops up is says not responding. Any advice?
Can you explain how to set up an exit function, to exit from a running python3 program from a users input (say shift plus key combination) without raising an error and giving a clean exit? I am thinking about a program running in idle.
This is and excellent video, well explained, Thanks!
@Corey Schafer i followed your sublime 3 steup video and setup as it mention but whenver i run code without any import statement i get error like this
/usr/local/bin/python3: can't find '__main__' module in ''
please help me to fix
Very helpful, thanks for sharing! I've been using Python for years, mostly v2 and this helps push me to switch 100% to Python v3 so I can curb my old bad habits.
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!
How's your job going today, 3 years later? :D
is there a command that deletes all indentation so you can re-indent, regardless of editor?
I didn't understood what program you suggest to help us checking the errors
Saved me from too much frustration...
I have one question about the default argument. Why it reset the list to none each time you run the function?it contradicts with what you said that it runs the default argument one and only once.
It is still setting the values to the default value every time, but they are only evaluated once. So if it is set to a value like None then it will get set to None by default if no arguments are provided. But if it's set to an empty list then it will create that new list once, and then it will get set to that same list by default if no arguments are provided. Since lists are mutable, you will be able to see that original list being modified. You won't be able to tell with immutable data types because they can't be modified.
I really like this explanation in this StackOverflow answer... I should have incorporated it into the explanation:
stackoverflow.com/questions/10676729/why-does-using-arg-none-fix-pythons-mutable-default-argument-issue
Good stuff. Only criticism is that it's Spider-Man. ;)
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.
Two points that interact in ways that seem quirky till you "get" the Python idiom.
The default value is remembered from creation of the function.
The default given and remembered is mutable: that means if you change the value you have changed the default.
In C terms think of it as the address which at the time of creation points to an empty linked list. If you add to the list the address remains the same but the contents vary. The implentation is not quite the same, but that's the basic idea.
That idea is helpful in making the transition from C (at least I found it so) but try to move on as soon as you can to thinking in Python terms: that that's just what mutable objects do: a mutable object can have different values over time.
Liked before "Hey there..."
useful
please help me how to fix badzipfile error using instapy
Can anyone kindly tell me what is the color scheme and theme is he using in sublime?
Material Dark Theme and Predawn Color Scheme
@@coreyms Thanks Corey .. Great Job ...
can you make tutorial about getting certificate in django heroku deployment?
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
Great
Thanks a lot for the effort you put into your quality videos, your teaching style is awesome but please can you do something on Django e-commerce website?
17:01 wade isn’t a hero he’s a villain who goes after other villains
Wade aka deadpool is an anti hero. So , he's technically still a hero
says not to name variables as module names (/ function names), names a variable time when importing the time module
Mutable default args make recursion memoization nice and easy. ;)
They also make it easy to get unintended recursive effects...
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.
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
@Matt Bergman Right.