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!
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.
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 Corey, your videos have helped me to build clear python foundations. I always get to your channel for clarification and learning! Excellent work
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 !
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....
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
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.
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
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 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
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?
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)
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.
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.
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
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.
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!
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.
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.
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
Please don't. There are millions of tutorials on Scikit-Learn and it is likely not his field. Please keep doing your awesome Python and devops oriented tutorials which you're perfect at. I have personally learnt so much from you.
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
@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
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.
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?
I still don't understand the mistake with default arguments... emp_list is supposed to be a local variable of that function, how can it survive multiple function calls?
The default value is stored at a memory address that is created only once, when the function is declared. Every time you call the function, you create a new local variable emp_list, but it will always point to that particular memory address by default. The local variable doesn't survive between function calls, but the default value that it points to does.
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 RUclips 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!
That naming conflict issue caused me so much confusion in the past. Nice tips Corey.
Always learn something new from your videos, even stuff I didn't know I wanted..lol. Great videos Corey mate!
Nice, I love it. I'm learning new things in Python all the time. Please keep up these videos. Thanks Corey.
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.
You are excellent teacher Corey. Many thanks for crisp and clear information with apt words.
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!
Great work - the mutable default argument issue is commonly asked on quizzes
Love the video Corey keep them coming!
Thanks Corey, your videos have helped me to build clear python foundations. I always get to your channel for clarification and learning! Excellent work
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 !
Really useful stuff! Thanks Corey!
Nice video!!
Continue with this quality.
Thank you!
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!
You should cover circular import dependencies in one of your videos. That’s always a good refresher.
This cleared up some things for me, thanks so much Corey!
this video you made is one of best to resolving our problems during learning your course
Always the best! Thank you Corey!
Great tutorial. Thank you Corey.
Yet another Great video. Always learning somthing new. Thanks!
You're really helping me out! I am super grateful!
the best pythonist ever. thank you corey
Thanks Corey, useful video
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!!
Impressive to watch these tips which I'm not aware so long time..especially naming convention potential risks...Thank you !
Thank you, very helpful!
Amazing gotchas! Thank you sir!
Thanks . The tips were quite useful.
I love your videos...please keep them coming they are very helpful
Thank you very much .This was very helpful to me.
Great tips!!
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....
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
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.
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
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
great tips!
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 would be the happiest man in the world if you make it a series
Looks simple but could give a lot of headaches. Thanks for the video.
18:20 I would also say that unzipping in a for loop (for name, hero in identities) doesn't work in Python 2 either
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?
Thanks for Skillshare. I just signing up to explore the courses :)
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
Thank you so much!
Many thanks
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
Great video! I should watch more of Corey's videos.
Naming your string as str or a list of things as list is a sure shot way of getting crazy...
it's useful thanks
thanks!
Thanks man, did you do some video about PEP8?
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)
Hi Corey, please make video on multiple inheritance and common problems associated with it
Hello Corey... Could you please make videos on data structures and algorithms
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.
14:52 - Wow, that is REALLY annoying. Coming from PHP, this would have driven me mad, and probably still will! Thanks for sharing.
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.
the list thing was very useful
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?
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
Hi Corey, is there a Numpy playlist in your contents, i couldn't find one in your website and in youtube
This is and excellent video, well explained, Thanks!
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!
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.
thank you :)
Default arguments was a surprise, good one 👍
Hey I created a simple turtle screen but when the screen pops up is says not responding. Any advice?
Good stuff. Only criticism is that it's Spider-Man. ;)
Hey Dude.!! Can u please help to sort a list in an ascending order ..with taking two loops...
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
I didn't understood what program you suggest to help us checking the errors
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.
is there a command that deletes all indentation so you can re-indent, regardless of editor?
useful
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..."
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.
Corey, please start Scikit-Learn tutorials!
Please don't. There are millions of tutorials on Scikit-Learn and it is likely not his field. Please keep doing your awesome Python and devops oriented tutorials which you're perfect at. I have personally learnt so much from you.
@@gh0oo there are million tutorials of Python, but everybody looking for Corey's tutorials!
Saved me from too much frustration...
Mutable default args make recursion memoization nice and easy. ;)
They also make it easy to get unintended recursive effects...
can you make tutorial about getting certificate in django heroku deployment?
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
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
Great
Can you make a video about naming variables - programmer's hardest challenge 😅😂?
@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
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.
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?
I still don't understand the mistake with default arguments...
emp_list is supposed to be a local variable of that function, how can it survive multiple function calls?
There is still some confusion about this from several people. Perhaps I will make a clarification video and show this more in-depth.
The default value is stored at a memory address that is created only once, when the function is declared. Every time you call the function, you create a new local variable emp_list, but it will always point to that particular memory address by default. The local variable doesn't survive between function calls, but the default value that it points to does.
Instead of capturing the iterator items in a list, another way to access the items again is to call zip again.