hello everybody and welcome back so in today's video i'm going to be showing you five python bad practices that you should avoid now these are things that many people do not actually know are bad practices they seem normal or kind of usual or natural to do but can lead to a lot of complications errors or just messy and unreadable code so with that said let's go ahead and dive into the video after a quick word from our sponsor before we get started i need to thank vidyard for sponsoring this video vidyard provides video tools built for improving communication and making remote work easier vidyard's video creation tools let you create and stream videos seamlessly so that you can better communicate with your employees or co-workers vidyard provides a free chrome extension and a desktop application that lets you record your audio video screen and all combinations of the above you can also upload existing videos to vidyard a great feature of vidyard is once you stop your recording it's automatically uploaded to vidyard so you can attach an email slack channel or wherever else you'd like to share it vidyard can be used to quickly log a bug while providing a demo ask detailed questions about code and to get feedback quicker from your team vidyard is perfect for senior leaders employee communication and for creating training in hr videos not only do vidyard videos add a personal touch to communication but they also have detailed analytics and security settings so you can track engagement and limit access to sensitive content vidyard is also used for sas sales and marketing and has all kinds of solutions for any use case vidyard is used by microsoft shopify linkedin and thousands of other large companies and you can get started with it yourself for free today by clicking the link in the description all right so let's move on to our first python bad practice which is mutable default parameters so this bad practice involves using a mutable object as the default parameter for a parameter inside of a function or a method now before i go any further with the explanation just have a look at this code and take a guess at what you think the output is going to be so pause the video if you need to i'm going to explain it now so i'm assuming that most of you would guess that what the output of this should be is one and then inside of a list one and then two and inside of a list two now this is actually not what the output is but intuitively that's kind of what it looks like right so let me stop here and run the code and show you what the output actually is so the output is one inside of a list one two inside of a list one comma two so that's a little bit strange why are we getting one comma NUMBER_TOKEN as the second result here well the reason why we're getting that is because we're using a mutable default parameter so if this was not a mutable object or this operated in the way that we thought it should operate then what would happen is when we call this function a new empty list would be created and stored in the parameter numbers we would append the number that we passed here to that list we then print the number print that list and then return it but since this is a mutable object this is not being recreated every time we call this function and so on the first function call we have this list object and on the sec second function
START_SPONSOR_TOKEN after a quick word from our sponsor before we get started i need to thank vidyard for sponsoring this video vidyard provides video tools built for improving communication and making remote work easier vidyard's video creation tools let you create and stream videos seamlessly so that you can better communicate with your employees or co-workers vidyard provides a free chrome extension and a desktop application that lets you record your audio video screen and all combinations of the above you can also upload existing videos to vidyard a great feature of vidyard is once you stop your recording it's automatically uploaded to vidyard so you can attach an email slack channel or wherever else you'd like to share it vidyard can be used to quickly log a bug while providing a demo ask detailed questions about code and to get feedback quicker from your team vidyard is perfect for senior leaders employee communication and for creating training in hr videos not only do vidyard videos add a personal touch to communication but they also have detailed analytics and security settings so you can track engagement and limit access to sensitive content vidyard is also used for sas sales and marketing and has all kinds of solutions for any use case vidyard is used by microsoft shopify linkedin and thousands of other large companies and you can get started with it yourself for free today by clicking the link in the description END_SPONSOR_TOKEN