10 Python Tips and Tricks For Writing Better Code
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:
skl.sh/coreyschafer
In this Python Programming video, we will be going over 10 tips and tricks for writing Pythonic code. Here are the timestamps for each topic we will cover...
1) Ternary Conditionals - 0:34
2) Underscore Placeholders - 2:13
3) Context Managers - 4:25
4) Enumerate - 6:50
5) Zip - 8:52
6) Unpacking - 13:02
7) Setattr/Getattr - 19:08
8) GetPass - 26:24
9) Python dash m - 29:18
10) Help/Dir - 33:17
Context Managers Tutorial - • Python Tutorial: Conte...
Sys.path Tutorial - • Python Tutorial for Be...
✅ Support My Channel Through Patreon:
/ coreyms
✅ Become a Channel Member:
/ @coreyms
✅ One-Time Contribution Through PayPal:
goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
www.amazon.com/shop/coreyschafer
▶️ You Can Find Me On:
My Website - coreyms.com/
My Second Channel - / coreymschafer
Facebook - / coreymschafer
Twitter - / coreymschafer
Instagram - / coreymschafer
#Python
Пікірлер: 985
To save you time, I put a list of all of the tips 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/coreyschafer
@knownwolf
5 жыл бұрын
Thank you for the timestamps!
@mrityunjayahiremath3951
5 жыл бұрын
Hey Corey, please make a video on MRO (Method Resolution Order) in Python
@almohtarifchannel6702
5 жыл бұрын
Corey Schafer how we can loop 2 lists witout same lenth
@coreyms
5 жыл бұрын
Like I was saying in the video, zip will stop after the shortest list is depleted. zip_longest from the itertools module will go to the end of the longest list and have filler values for the shorter lists. Watch my video on itertools to see an example.
@dharaneeshwaranravichandra6159
5 жыл бұрын
Please make a video on "How Django processes a request ?"
I'm 79 years old, been studying Python for about 6 months, and I got to tell you I get so damned exited with the stuff I learn from you - no other teacher, paid or free, has come close. I just hate to tear myself away from videos like this! I don't have a lot of money, but I'm gonna send you a few bucks - buy a toy for your beautiful dog. :)
@deeshu3456
3 жыл бұрын
God bless you... ☺️✨. Shine on...
@tobycherry47
3 жыл бұрын
@@joshkanyinda5569 tf is wrong with you. he's doing whatever he wants, making the most of life, unlike you obviously.
@NetEng89
3 жыл бұрын
@@joshkanyinda5569 What a useless comment...
@ididntgetthejoke3587
3 жыл бұрын
@@NetEng89 agreed
@pillowrabbit8324
3 жыл бұрын
tf is wrong with you
Dude, underscores can be used to delim numbers!? Literally life-changing tip, thank you!
@MykhailoK-sh6sm
5 жыл бұрын
Same XDDD
@zahirjacobs716
5 жыл бұрын
only python 3.6+
@elghazouanimohammed6639
5 жыл бұрын
Can you give me an exemple where you need that please ?
@Demonslay335
5 жыл бұрын
@@elghazouanimohammed6639 I deal with cryptography and thus large numbers a lot. Having some human readable constants is nice, such as 2**32 if it were written out. Sometimes it even just helps for understanding "oh, it's like a billion" without having to break out the cursor to count each zero.
@bsmaheshkumar5328
4 жыл бұрын
It is used to separate the multiple string. Ex. full_name = 'John'
Enjoy! 1) 0:34 - ternary operator ; 2) 2:13 - Underscores in Numeric Literals + about f-string; 3) 4:29 - context manager ; 4) 6:49 - enumerate function ; 5) 9:01 - zip function ; 6) 13:46 - unpacking tuples (use asterisk and underscore); 7) 19:11 - getting and setting attributes to object (setattr, getattr ); 8) 26:24 - getpass instead input (read from keyboard) ; 9) 29:22 - run python with dash m in terminal (python -m ...); 10) 32:32 - built-in functions (help, dir etc)
@eujnia
4 жыл бұрын
loviuuuuuuuuu
@ardonjr
4 жыл бұрын
@@eujnia This is literaly in the description
@eujnia
4 жыл бұрын
@@ardonjr can u act like a normal person and just ignore me?
@za6604
3 жыл бұрын
@@ardonjr Mobile users can't click the timestamps in the description.
@ardonjr
3 жыл бұрын
@@za6604 Uh yes I can? I'm typing this from my mobile phone..
My favourite Channel for learning python
@fefemorte
5 жыл бұрын
Mine too, extremely good explanations
@medi7573
5 жыл бұрын
And best on KZread
@sandeepvk
5 жыл бұрын
Indeed ! he is quick to the point and no baloney
@vorrade
3 жыл бұрын
@@dr.rijjaayaz8160 Sorry, but the narrative voice is not nearly as pleasant as Corey Schafer's
Your videos are amazing. So well explained. I feel I learn to code better every time I watch your videos, even if I already know the modules you introduce. Thank you so much!
The best python teacher ...thanks corey sir..
This is incredible. I absolutely love your delivery - you are such a good speaker. I've used your videos as a refresher and I want to thank you so much for your great archive of helpful videos!
As a Python beginner - but not a beginner in programming - this video was great! Awesome explanation, thank you!
I've been coding in Python over a year now, and was expecting to only see one or two new things. BUT I LEARNED SO MUCH MORE ! Thank You!
Those tips on unpacking were mindblowing to me; i never knew we could use those syntaxes. Great video!
As a new Python learner, I find your videos are the most interesting, clear and throughout! Glad that you still making python videos. Thank you!
Thanks Corey! I'm in the process of learning Python, and this definitely helps. Well done, sir!
Wow. Figured I'd watch a random python tips video instead of memes and found exactly what I needed for one of my projects. Thanks man! Awesome vid!
Fantastic, 40 minutes of my life well spent.
I've been coding with python for a while, I've messed around with neural networks, yet somehow I didn't know some of these amazing tips. Thanks!
You are the best as usual Corey. Thank you so much for this valuable tutorial, you are really a life saver
Thank you for everything you do, Corey. Once again, I've learned an absurd amount of information in less than an hour.
Corey, just thanks, man. That is all I can say for the content that you make here. I have learned so much from you
@coreyms
5 жыл бұрын
Thanks for the comment! Glad you've learned a lot!
Excellent video. I learned some of these the hard way writing spaghetti code and I think it's refreshing to have a breakdown with examples like these. Great work!
Your content is so unbelievably good! Thank you so much for all that you've taught me. You speak so clearly, describe concepts so well, demonstrate with perfection, you're incredible!
Dude!! What a great video! Thanks you so much. Please, continue bringing more videos
Reading about those things (as someone who started with C and co) it's easy to forget. This video is a great summary of all the helpful functionalities we forget about.
Thank you for this one! Exactly what I needed to help advance my code refactoring sessions.
You are the best teacher ever Corey! Learning tips and tricks like these can save a programmer a lot of time, so I really appreciate videos like these
@vaibhavkrkm
4 жыл бұрын
Yea👍
His tutorials are exponentially much better than most of the Udemy & Coursera courses. You're doing a Great job Corey you're having an impact ❤️ Keep it up.
Some of the best Python content out there. Absolutely love learning Python alongside your videos and teachings.
day by day I am falling more and more in love with your teaching style
The work you do is priceless. Thank you so much, Corey! You are really wonderful teacher, who keeps to inspire me and others to move toward being a better developers.
@coreyms
5 жыл бұрын
Thanks for the kind words!
Nice video... I didn't know about the start in enumerate. And that unpacking list bit was really good.
Thanks for the timestamps! Makes for a great reference video to save. And more likely to find when searching
Thank you Corey, your tutorials are simply great. Always spot on with very good examples.
Great tips and tricks! The best python instructor!
Great video, thank you for sharing!
@toptoendgamer7360
3 жыл бұрын
I watch your videos
@misterjaypeasmith
3 жыл бұрын
Praise from Caesar 😅
Excellent information as usual. Definitely picked up some new tricks here. Thanks for all you do Corey. You really have a gift for teaching.
I love these videos you make. They inspire me to try more Python things in my code.
Hey! Corey that was great video tutorial . Get to learn lot of new things. Happy Pythoning.
KZread : 10 python tips and tricks... Me : Leave me alone please KZread : ...from Corey Schafer Me : *Instaclick*
@coreyms
5 жыл бұрын
Haha, thanks!
so far, this is the best python channel i ever saw, best explanation, clean nice voice, thank you mr Corey
I've worked with Python for a few years and have seen a lot of code out there but I didn't know all of the tips here. Thanks.
A tip about unpacking with the star is great. Thanks a lot.
Was sitting yesterday, passing values to object attributes(13of them), and ended up looping around dict and doing this: For item in dict: obj.attribute=item[‘index1’] obj.attribute2=item[‘index2’] Wish I knew about setattr... Thank you !!!Mr. Schafer
Hey, Corey! Greetings from Mother Russia 👋🏻 Thank you for what you are doing! No water, just a facts with super clear examples. You’re making KZread better!
Ran into the same setattr problem couple times before, great video!
Thanks Corey your channel isTHE best Channel for learning python please if it possible a playlist for Data structure & Algorithms in python
thanks for the free knowledge, from an aspiring developer
Brilliant tips for typing code with high quality! New to Python! But i worked as a developer for a company for 1 year with AngularJS, I wish people cared more about this type of things! Thanks!
Corey is a genius at knowing what it is we need to know and knowing how to explain it simply and clearly.
And I am still learning new cool stuff you can do in Python :) Thank you!
Thanks mate. You just saved me tons of hours of hating myself. Great job!
Corey thanks for all your tutorials videos. Thy are really helpful.. Since I am a self taught without any background of programming..
Just came across this channel and I subscribed right away. This is my second video. I love your teaching 👍
Your videos are so high quality! All the info was very useful specially the dir(). God I wish i knew that earlier xD Thank you so much :) I followed your django tutorials and now have 4 good personal projects under my belt! Your tutorials were my foundation of Django. One thing I'd really want you to cover is unit tests. They seem to be a huge part of companies and I think its an important topic to cover and would be helpful to other viewers as well. Thank you so much once again for producing such high quality videos for us
@jaideepshekhar4621
5 жыл бұрын
Yes, what are unit tests?
Although I didn't know about zip (8:52) and it does seem pretty helpful, it looks like you could get an equally organized structure if you use a dictionary instead since the two lists are inherently related and do something like: for name, hero in dictionary_name.items(): In any case, great video and I definitely managed to learn some things
The quality of this content.. insane. Thanks, Corey.
Corey, wanted to give a like for every tip&trick out there... Thanks a bunch!!!
Best Python Learning Channel!
Great video! Many thanks. Strong emphasis on the statement: You don't have to know everything, but it's more important to be able to find information and use it.
Man, your explanations are so clear and the tips are actually helpful. Thank you very much!
Totally awesome video! Thanks Corey!
Great flow dude..
I've worked with Python for many years, and some of the features mentioned here are only in the most recent versions of python (like f-strings). I work in environments that have older versions of python (even the now obsolete Python2.7) without these features I think it would have been helpful if the version of Python where the feature was introduced was mentioned in the video. This is not meant to be a criticism, this video is great!
Another incredible video. You never ever disappoint, Corey. Well done.
Thank you very much for sharing this, as a data analyst using python on a daily basis some of these would make my life a lot easier! :D
First of all, I have to say that I'm very thankful for this videos. I am from Argentina and the part of "nosetuid" made me laugh a lot just because I instictibly separated it like "no se tu id" witch is Spanish for "I don't know your id"; I know, is silly, just wanted to share it with the comments people
These actually helped me quite a lot and you presented the explanations well. Thank you.
As always, great stuff Corey!
Hi, can we please have tips on how can we make our code more reusable and understandable if we're working on a large scale project? Thanks. As always, the best tutorials on YT!
5 жыл бұрын
Comment your Code and split your Code into small classes and files
The package "Terminus" is a package that allows you to run the command line as a panel in sublime text 3. I personally use it in combination with WSL on my windows pc to simulate a Linux setup without having to run a VM.
Thank you for this trick, this is just I was looking for, and thank you for screen size, because there are tons of videos, where I can't see nothing, but your is great, thank you my friend.
Super useful! Thanks a lot, Corey!
You were sent from heaven.
from my_heart import thank thank.you('for this brilliant and plain way of explaining python usage')
I was told that unpacking is going to be very useful. Thanks for the concise video of its usage!!
You got the best tutorials i have found so far thanks for the good work man
VEry cools zip tips
only 4 minutes in and I went off a wikipedia binge tangent that left me knowing everything about large number names in different scales and languages
Thank you for providing such great content! After a brilliant explanation in the OOP series, I thought nothing else would surprise me :D but this video is from another universe
Very good, thank you. Helpful, concise and actually something new. KZread is full of Python tips/tricks/how-tos from amateurs that cover the first 5 pages of a good textbook, your tips are actually practically useful to beginners and intermediates alike.
Will u make a vid on tkinter or any other GUI?
Just FYI, the underscore number separator only available from Python v3.6+
@climatechangedoesntbargain9140
4 жыл бұрын
...
@ReddoX30
3 жыл бұрын
Thanks for pointing that out!
@ricardocebreros7142
3 жыл бұрын
Also the f string place holder It was added with v.3.6 Older versions have to use “ “.format()
we need part2 Corey..It's really an awesome video.. Waiting eagerly for part2,3,4,5, --- infinity .. :) Keep posting awesome stuff Corey.
Great tutorial! A weekly '10 tips & tricks' would be VERY welcome and popular. You are an excellent teacher. :)
nose tuid xD. Exactly the way I read it as well the first time.
Wait, Clark Kent is Superman?? no way, I've seen him, he weares glasses...
This guys knowledge completely blows other tutorials out of the water! I know I’m late to the game Corey but your content is truly amazing thank you from 2023
I'm just getting started by taking a couple online courses. Your videos really help to clarify the subject matter. You have the best Python videos on KZread.
@coreyms
5 жыл бұрын
Thanks! Good luck getting started in programming!
These are like the new 10 commandments
maybe this is just me being crazy, but i ALWAYS do loops like this: for i in range(len(names)): print(i, names[i]) but idk
@Bryan-bh7cy
4 жыл бұрын
nub...
@jankreitzscheck9914
4 жыл бұрын
So do I. I'm not a professional programmer, this works for me, no idea whether it is the ideal way of doing things.
@ycliu4046
4 жыл бұрын
This would be faster than enumeration. You could timeit yourself. I would prefer this one to enumeration
@krishnakumarshankar4576
4 жыл бұрын
Why can't you do this
@SorinOltean77
3 жыл бұрын
@Parker Anderson: your method is correct for sure but is not pythonic. The Python way of doing things tends to simplicity in code writing, hence the enumerate function. Even the fact that you can loop through a list with just "for item in items:" is something really easy to write and understand later.
I clicked on this video thinking I would learn one or two things, but I've been shocked and impressed by each tip, this was very helpful!
I just solved a problem using zip thanks to this video. Thank you..
Have I told....you lately....that I love you? Hahaha
@shazkingdom1702
5 жыл бұрын
hahaha... he deserves the song... 🎶
NOSETUID got me. hahaha
Man, thank you. You showed few tips I was looking for a long time.
Thank you so much for setattr and getattr. It is amzing. Changed my whole codes.
"Not all python modules are this thicc." Oh just like how not all youtube videos are this thicc? 🙂
how can I give you infinite likes? Hello from brazil!!!
@ovilambru9058
3 жыл бұрын
Make a script for it...
Another super video. So easy to follow along. Thanks mate
I must say you 've provide very handful tips. After seeing this video I'm going to change my coding style. Your tips are certainly going to save lot of time.
I appreciate your videos. But there are 4000 KZread videos on fundamentals of python, however only about 5 on how to solve issues. When I take a class or an interview they ask me to solve a problem and not syntax questions. I wish there were more videos on how to solve problems so I can see how the logic works and how to approach solving the problem.