10 Python Tips and Tricks For Writing Better Code
Вставка
- Опубліковано 24 бер 2019
- 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
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
Thank you for the timestamps!
Hey Corey, please make a video on MRO (Method Resolution Order) in Python
Corey Schafer how we can loop 2 lists witout same lenth
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.
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. :)
God bless you... ☺️✨. Shine on...
@@joshkanyinda5569 tf is wrong with you. he's doing whatever he wants, making the most of life, unlike you obviously.
@@joshkanyinda5569 What a useless comment...
@@NetEng89 agreed
tf is wrong with you
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)
loviuuuuuuuuu
@@eujnia This is literaly in the description
@@ardonjr can u act like a normal person and just ignore me?
@@ardonjr Mobile users can't click the timestamps in the description.
@@za6604 Uh yes I can? I'm typing this from my mobile phone..
Dude, underscores can be used to delim numbers!? Literally life-changing tip, thank you!
Same XDDD
only python 3.6+
Can you give me an exemple where you need that please ?
@@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.
It is used to separate the multiple string. Ex. full_name = 'John'
My favourite Channel for learning python
Mine too, extremely good explanations
And best on UA-cam
Indeed ! he is quick to the point and no baloney
@@dr.rijjaayaz8160 Sorry, but the narrative voice is not nearly as pleasant as Corey Schafer's
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!
As a Python beginner - but not a beginner in programming - this video was great! Awesome explanation, thank you!
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!
Thanks!
Corey, just thanks, man. That is all I can say for the content that you make here. I have learned so much from you
Thanks for the comment! Glad you've learned a lot!
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
Yea👍
Those tips on unpacking were mindblowing to me; i never knew we could use those syntaxes. Great video!
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.
Thanks for the kind words!
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!
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.
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 new Python learner, I find your videos are the most interesting, clear and throughout! Glad that you still making python videos. Thank you!
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!
Thank you for everything you do, Corey. Once again, I've learned an absurd amount of information in less than an hour.
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!
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!
Fantastic, 40 minutes of my life well spent.
The best python teacher ...thanks corey sir..
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.
Dude!!
What a great video!
Thanks you so much.
Please, continue bringing more videos
You are the best as usual Corey. Thank you so much for this valuable tutorial, you are really a life saver
Great video, thank you for sharing!
I watch your videos
Praise from Caesar 😅
Thanks Corey! I'm in the process of learning Python, and this definitely helps. Well done, sir!
day by day I am falling more and more in love with your teaching style
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 that was great video tutorial . Get to learn lot of new things.
Happy Pythoning.
Thank you for this one! Exactly what I needed to help advance my code refactoring sessions.
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!
A tip about unpacking with the star is great. Thanks a lot.
Some of the best Python content out there. Absolutely love learning Python alongside your videos and teachings.
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 UA-cam better!
Nice video... I didn't know about the start in enumerate. And that unpacking list bit was really good.
Great tips and tricks! The best python instructor!
The quality of this content.. insane. Thanks, Corey.
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
Yes, what are unit tests?
Thanks Corey your channel isTHE best Channel for learning python
please if it possible a playlist for Data structure & Algorithms in python
so far, this is the best python channel i ever saw, best explanation, clean nice voice, thank you mr Corey
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.
thanks for the free knowledge, from an aspiring developer
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
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
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!
Best Python Learning Channel!
Thanks mate. You just saved me tons of hours of hating myself. Great job!
Great tutorial! A weekly '10 tips & tricks' would be VERY welcome and popular. You are an excellent teacher. :)
Excellent information as usual. Definitely picked up some new tricks here. Thanks for all you do Corey. You really have a gift for teaching.
UA-cam : 10 python tips and tricks...
Me : Leave me alone please
UA-cam : ...from Corey Schafer
Me : *Instaclick*
Haha, thanks!
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.
Thanks for the timestamps! Makes for a great reference video to save. And more likely to find when searching
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 UA-cam.
Thanks! Good luck getting started in programming!
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!
Thank you Corey, your tutorials are simply great. Always spot on with very good examples.
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.
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
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.
Corey, wanted to give a like for every tip&trick out there... Thanks a bunch!!!
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!
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!
Comment your Code and split your Code into small classes and files
from my_heart import thank
thank.you('for this brilliant and plain way of explaining python usage')
Ran into the same setattr problem couple times before, great video!
You got the best tutorials i have found so far thanks for the good work man
You were sent from heaven.
VEry cools zip tips
I love these videos you make. They inspire me to try more Python things in my code.
Man, your explanations are so clear and the tips are actually helpful. Thank you very much!
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
Will u make a vid on tkinter or any other GUI?
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 👍
Just FYI, the underscore number separator only available from Python v3.6+
...
Thanks for pointing that out!
Also the f string place holder
It was added with v.3.6
Older versions have to use “ “.format()
nose tuid xD. Exactly the way I read it as well the first time.
The best programming teacher I've found in UA-cam!
we need part2 Corey..It's really an awesome video.. Waiting eagerly for part2,3,4,5, --- infinity .. :) Keep posting awesome stuff Corey.
Have I told....you lately....that I love you? Hahaha
hahaha... he deserves the song... 🎶
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
nub...
So do I. I'm not a professional programmer, this works for me, no idea whether it is the ideal way of doing things.
This would be faster than enumeration. You could timeit yourself. I would prefer this one to enumeration
Why can't you do this
@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.
Very good, thank you. Helpful, concise and actually something new. UA-cam 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.
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
These are like the new 10 commandments
Wait, Clark Kent is Superman?? no way, I've seen him, he weares glasses...
I know this is an older video, but I found it really helpful. I'm pretty much making all the programming mistakes you're talking about....now I'm cleaning them all up...thanks.
Thank you so much for setattr and getattr. It is amzing. Changed my whole codes.
NOSETUID got me. hahaha
how can I give you infinite likes?
Hello from brazil!!!
Make a script for it...
Another incredible video. You never ever disappoint, Corey. Well done.
These actually helped me quite a lot and you presented the explanations well. Thank you.
"nose tuid" I am gonna remember it this way now. 😂😂😂😂
"Not all python modules are this thicc."
Oh just like how not all youtube videos are this thicc? 🙂
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
As always, great stuff Corey!
I appreciate your videos. But there are 4000 UA-cam 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.
The whole time my mind was like:
*Whaaaaaaaaaaa-*
Totally awesome video! Thanks Corey!
I was told that unpacking is going to be very useful. Thanks for the concise video of its usage!!
I also saw nose-t-uid