Тёмный

10 Python Tips and Tricks For Writing Better Code 

Corey Schafer
Подписаться 1,4 млн
Просмотров 1,4 млн
50% 1

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/coreysc...
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...
▶️ You Can Find Me On:
My Website - coreyms.com/
My Second Channel - / coreymschafer
Facebook - / coreymschafer
Twitter - / coreymschafer
Instagram - / coreymschafer
#Python

Опубликовано:

 

13 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 984   
@coreyms
@coreyms 5 лет назад
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
@knownwolf 5 лет назад
Thank you for the timestamps!
@mrityunjayahiremath3951
@mrityunjayahiremath3951 5 лет назад
Hey Corey, please make a video on MRO (Method Resolution Order) in Python
@almohtarifchannel6702
@almohtarifchannel6702 5 лет назад
Corey Schafer how we can loop 2 lists witout same lenth
@coreyms
@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
Please make a video on "How Django processes a request ?"
@expat2010
@expat2010 3 года назад
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
@deeshu3456 3 года назад
God bless you... ☺️✨. Shine on...
@tobycherry47
@tobycherry47 3 года назад
@@joshkanyinda5569 tf is wrong with you. he's doing whatever he wants, making the most of life, unlike you obviously.
@cloakedvisor
@cloakedvisor 3 года назад
@@joshkanyinda5569 What a useless comment...
@ididntgetthejoke3587
@ididntgetthejoke3587 3 года назад
@@cloakedvisor agreed
@pillowrabbit8324
@pillowrabbit8324 3 года назад
tf is wrong with you
@Demonslay335
@Demonslay335 5 лет назад
Dude, underscores can be used to delim numbers!? Literally life-changing tip, thank you!
@MykhailoK-sh6sm
@MykhailoK-sh6sm 5 лет назад
Same XDDD
@zahirjacobs716
@zahirjacobs716 5 лет назад
only python 3.6+
@elghazouanimohammed6639
@elghazouanimohammed6639 5 лет назад
Can you give me an exemple where you need that please ?
@Demonslay335
@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
@bsmaheshkumar5328 5 лет назад
It is used to separate the multiple string. Ex. full_name = 'John'
@BohdanKokovych
@BohdanKokovych 4 года назад
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
@eujnia 4 года назад
loviuuuuuuuuu
@ardonjr
@ardonjr 4 года назад
@@eujnia This is literaly in the description
@eujnia
@eujnia 4 года назад
@@ardonjr can u act like a normal person and just ignore me?
@za6604
@za6604 4 года назад
@@ardonjr Mobile users can't click the timestamps in the description.
@ardonjr
@ardonjr 4 года назад
@@za6604 Uh yes I can? I'm typing this from my mobile phone..
@wolfisraging
@wolfisraging 5 лет назад
My favourite Channel for learning python
@medi7573
@medi7573 5 лет назад
And best on RU-vid
@sandeepvk
@sandeepvk 5 лет назад
Indeed ! he is quick to the point and no baloney
@vorrade
@vorrade 3 года назад
@@dr.rijjaayaz8160 Sorry, but the narrative voice is not nearly as pleasant as Corey Schafer's
@EVGrinds
@EVGrinds 4 года назад
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!
@brainplot
@brainplot 5 лет назад
As a Python beginner - but not a beginner in programming - this video was great! Awesome explanation, thank you!
@petursteinn9718
@petursteinn9718 5 лет назад
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!
@coreyms
@coreyms 5 лет назад
Thanks!
@isidaruk1408
@isidaruk1408 5 лет назад
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
@coreyms 5 лет назад
Thanks for the kind words!
@blazecoolman
@blazecoolman 5 лет назад
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
@coreyms 5 лет назад
Thanks for the comment! Glad you've learned a lot!
@Bigbadwolf144
@Bigbadwolf144 3 года назад
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.
@archstampton5910
@archstampton5910 5 лет назад
Fantastic, 40 minutes of my life well spent.
@realchrishawkes
@realchrishawkes 5 лет назад
Great video, thank you for sharing!
@toptoendgamer7360
@toptoendgamer7360 3 года назад
I watch your videos
@misterjaypeasmith
@misterjaypeasmith 3 года назад
Praise from Caesar 😅
@pawe1
@pawe1 4 года назад
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.
@smashies118
@smashies118 5 лет назад
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!
@jerrymiller1590
@jerrymiller1590 4 года назад
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
@vaibhavkrkm 4 года назад
Yea👍
@hungvunguyen8929
@hungvunguyen8929 5 лет назад
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!
@caio-jl6qw
@caio-jl6qw 5 лет назад
Those tips on unpacking were mindblowing to me; i never knew we could use those syntaxes. Great video!
@MegaTheDamir
@MegaTheDamir 5 лет назад
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
@md.akib5124
@md.akib5124 5 лет назад
day by day I am falling more and more in love with your teaching style
@TAlfonsoK
@TAlfonsoK 5 лет назад
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!
@kumarmayank8586
@kumarmayank8586 5 лет назад
The best python teacher ...thanks corey sir..
@pedro_6925
@pedro_6925 2 года назад
The quality of this content.. insane. Thanks, Corey.
@zperk13
@zperk13 5 лет назад
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!
@sheeeeeeeeeeesh
@sheeeeeeeeeeesh 4 года назад
IDK how but I have been using python for about 2(ish?) years now and most of these are brand new to me and HOLY CRAP DO THEY CHANGE SO MUCH
@o.sunsfamily
@o.sunsfamily 4 года назад
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.
@flavio4923
@flavio4923 2 года назад
The best programming teacher I've found in RU-vid!
@Ridistrict
@Ridistrict 5 лет назад
Thank you for everything you do, Corey. Once again, I've learned an absurd amount of information in less than an hour.
@antonlashov7893
@antonlashov7893 5 лет назад
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 RU-vid better!
@ItzSenaCrazy
@ItzSenaCrazy 5 лет назад
Dude!! What a great video! Thanks you so much. Please, continue bringing more videos
@unclebuddy
@unclebuddy 2 года назад
Corey is a genius at knowing what it is we need to know and knowing how to explain it simply and clearly.
@williamreames2228
@williamreames2228 4 года назад
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
@stephenneiswanger4827
@stephenneiswanger4827 Год назад
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
@computer_sciences
@computer_sciences 5 лет назад
Thanks Corey your channel isTHE best Channel for learning python please if it possible a playlist for Data structure & Algorithms in python
@JamBear
@JamBear 4 года назад
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!
@nasreddinehodja5930
@nasreddinehodja5930 5 лет назад
RU-vid : 10 python tips and tricks... Me : Leave me alone please RU-vid : ...from Corey Schafer Me : *Instaclick*
@coreyms
@coreyms 5 лет назад
Haha, thanks!
@I_Follow_Jesus
@I_Follow_Jesus 5 лет назад
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 RU-vid.
@coreyms
@coreyms 5 лет назад
Thanks! Good luck getting started in programming!
@ishpeace4886
@ishpeace4886 5 лет назад
You are the best as usual Corey. Thank you so much for this valuable tutorial, you are really a life saver
@kaitoti21
@kaitoti21 3 года назад
feels good to know some of this already as a somewhat beginner
@caseymccray3861
@caseymccray3861 5 лет назад
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
@jaideepshekhar4621 5 лет назад
Yes, what are unit tests?
@g3org3210
@g3org3210 4 года назад
Corey, wanted to give a like for every tip&trick out there... Thanks a bunch!!!
@oj43085
@oj43085 5 лет назад
Nice video... I didn't know about the start in enumerate. And that unpacking list bit was really good.
@thewhiterabbit661
@thewhiterabbit661 3 года назад
You got the best tutorials i have found so far thanks for the good work man
@AlexanderDemin
@AlexanderDemin 5 лет назад
A tip about unpacking with the star is great. Thanks a lot.
@MyYouthUk
@MyYouthUk 3 года назад
This is the first time I've intentionally sat through the sponsor segment at the end of a video... not because I'm interested in Skillshare... just because you've more than earned that time from me.
@jingyuchang1885
@jingyuchang1885 5 лет назад
Great tips and tricks! The best python instructor!
@bengbeng2005
@bengbeng2005 4 года назад
so far, this is the best python channel i ever saw, best explanation, clean nice voice, thank you mr Corey
@santiagolerin
@santiagolerin 4 года назад
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
@Jokeofdday
@Jokeofdday 4 года назад
lot of people know python but only few knows how to tech or deliver it.. 👍 best free python tutorial available across youtube and internet..
@brightsideofmaths
@brightsideofmaths 5 лет назад
And I am still learning new cool stuff you can do in Python :) Thank you!
@Mamuli_28
@Mamuli_28 3 года назад
ur accent is very easy to understand and calm! easily understood everything u taught!
@RufusVidS
@RufusVidS 3 года назад
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!
@gussta1
@gussta1 4 года назад
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.
@dmenace9288
@dmenace9288 5 лет назад
Thanks mate. You just saved me tons of hours of hating myself. Great job!
@betaman2009
@betaman2009 5 лет назад
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!
@jamesjung4440
@jamesjung4440 5 лет назад
thanks for the free knowledge, from an aspiring developer
@antonlinden5216
@antonlinden5216 5 лет назад
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!
@eeshsingh3336
@eeshsingh3336 5 лет назад
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
@somjji
@somjji 3 года назад
Thank you so much for setattr and getattr. It is amzing. Changed my whole codes.
@minghaotao6259
@minghaotao6259 5 лет назад
Best Python Learning Channel!
@seonwookim5391
@seonwookim5391 3 года назад
Thank you so much. You are the greatest teacher i’ve ever met
@AundreL
@AundreL 5 лет назад
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.
@azr_sd
@azr_sd 4 года назад
we need part2 Corey..It's really an awesome video.. Waiting eagerly for part2,3,4,5, --- infinity .. :) Keep posting awesome stuff Corey.
@anilkumarverma240
@anilkumarverma240 5 лет назад
Hey! Corey that was great video tutorial . Get to learn lot of new things. Happy Pythoning.
@csathys2
@csathys2 4 года назад
Hi Cory, just a few minutes into this video, your first 2 tips, use of ternary condition and enumerates, led me to come up with this class that would pretty much "act" like a substring on a list of elements. For example, if you wanted to just extract certain elements of a string. Full code is here: class mylib(): def __init__(self, list_a, start, end): self.list_a = list_a self.start = start self.end = end def getSubset(self): names = self.list_a en=enumerate(names) startpos=self.start endpos=self.end c=[] # initialize a new list for idx, name in en: # Append only if our criteria is satisfied. c.append(name) if (idx >= startpos and idx
@dudang5814
@dudang5814 5 лет назад
Just FYI, the underscore number separator only available from Python v3.6+
@climatechangedoesntbargain9140
...
@ReddoX30
@ReddoX30 4 года назад
Thanks for pointing that out!
@ricardocebreros7142
@ricardocebreros7142 3 года назад
Also the f string place holder It was added with v.3.6 Older versions have to use “ “.format()
@SHONNER
@SHONNER 5 лет назад
I love these videos you make. They inspire me to try more Python things in my code.
@aasensios
@aasensios 4 года назад
from my_heart import thank thank.you('for this brilliant and plain way of explaining python usage')
@HaileeMiu
@HaileeMiu 5 лет назад
Thanks for the timestamps! Makes for a great reference video to save. And more likely to find when searching
@spitalhelles3380
@spitalhelles3380 5 лет назад
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
@shegsdev
@shegsdev 4 года назад
Just came across this channel and I subscribed right away. This is my second video. I love your teaching 👍
@ghazanfarabidi4137
@ghazanfarabidi4137 5 лет назад
Great flow dude..
@WandererOfWorlds0
@WandererOfWorlds0 4 года назад
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.
@starecekmichal
@starecekmichal 5 лет назад
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.
@arizu1240
@arizu1240 Год назад
how do you explain that functions so easy? im having a hard time with that before with some guys here in yt but you teach me that in 3mins lol. thank you, what a madlad
@rohan352
@rohan352 5 лет назад
Will u make a vid on tkinter or any other GUI?
@ironmanlifts
@ironmanlifts 3 года назад
Thanks for the videos Corey, love your videos. Another way to do it is with this snippet --> methods_only_list = [attribute for attribute in dir(MyClass) if callable(getattr(MyClass, attribute)) and attribute.startswith('__') is False] print("Methods only are. ",methods_only_list)
@parkeranderson23
@parkeranderson23 4 года назад
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
@Bryan-bh7cy 4 года назад
nub...
@jankreitzscheck9914
@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
@ycliu4046 4 года назад
This would be faster than enumeration. You could timeit yourself. I would prefer this one to enumeration
@krishnakumarshankar4576
@krishnakumarshankar4576 4 года назад
Why can't you do this
@SorinOltean77
@SorinOltean77 4 года назад
@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.
@balamuruganthangam6059
@balamuruganthangam6059 4 года назад
Awesome tips in Python... Thanks for sharing this. It’s very useful tricks.
@kantulaev
@kantulaev 5 лет назад
VEry cools zip tips
@eduardogamboa9387
@eduardogamboa9387 5 лет назад
Ran into the same setattr problem couple times before, great video!
@cybergen2K
@cybergen2K 5 лет назад
You were sent from heaven.
@mehdia5810
@mehdia5810 2 года назад
As you said, these setattr and getattr are extremely helpful. Thanks!
@westfield90
@westfield90 5 лет назад
I appreciate your videos. But there are 4000 RU-vid 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.
@ddffdf4937
@ddffdf4937 3 года назад
man you just saved my life my python code will be a lot cleaner going forward
@pepinote14
@pepinote14 5 лет назад
Wait, Clark Kent is Superman?? no way, I've seen him, he weares glasses...
@sameerk12982
@sameerk12982 4 года назад
Very helpful tutorial...thank you very much...appreciated.
@TinkCSA
@TinkCSA 5 лет назад
nose tuid xD. Exactly the way I read it as well the first time.
@vaibhavkrkm
@vaibhavkrkm 4 года назад
36:49 U accidentally delivered one more tip than you said (at least for me), u typed exit() to exit Python from terminal, while I used to import sys first from os, and then do sys.exit().. Thanks, you are one of the best teachers for me!!!👍🤗
@sadbadmac
@sadbadmac 4 года назад
These are like the new 10 commandments
@Zwiesel66
@Zwiesel66 4 года назад
Thank you Corey, your tutorials are simply great. Always spot on with very good examples.
@kickflipz
@kickflipz 3 года назад
"Not all python modules are this thicc." Oh just like how not all youtube videos are this thicc? 🙂
@negarshahrokh9727
@negarshahrokh9727 4 года назад
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
@coreycarter5668
@coreycarter5668 5 лет назад
Have I told....you lately....that I love you? Hahaha
@shazkingdom1702
@shazkingdom1702 5 лет назад
hahaha... he deserves the song... 🎶
@uzeyir.suleymanov
@uzeyir.suleymanov Год назад
Thanks a lot Corey - 3+ years and it helps 🙌 At 12:30 we can use: for index, (name, hero, universe) in enumerate(zip(names, heroes, universes), start=1): print(f'{index}: {name} - {hero} - {universe}')
@jaymeetvasava7668
@jaymeetvasava7668 4 года назад
"nose tuid" I am gonna remember it this way now. 😂😂😂😂
@matthewweitzner8956
@matthewweitzner8956 3 года назад
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!
@KevObispo
@KevObispo 5 лет назад
NOSETUID got me. hahaha
@_indrid_cold_
@_indrid_cold_ 4 года назад
Some of the best Python content out there. Absolutely love learning Python alongside your videos and teachings.
@bernardo231
@bernardo231 5 лет назад
how can I give you infinite likes? Hello from brazil!!!
@ovilambru9058
@ovilambru9058 3 года назад
Make a script for it...
Далее
25 nooby Python habits you need to ditch
9:12
Просмотров 1,8 млн
Faites comme moi
00:14
Просмотров 1,4 млн
5 Good Python Habits
17:35
Просмотров 526 тыс.
5 Common Python Mistakes and How to Fix Them
29:19
Просмотров 289 тыс.
10 ULTIMATE Python Tips 🔥
16:42
Просмотров 66 тыс.
Python Tutorial: if __name__ == '__main__'
8:43
Просмотров 2 млн
Python 101: Learn the 5 Must-Know Concepts
20:00
Просмотров 1,1 млн
BASH scripting will change your life
14:18
Просмотров 1 млн
If __name__ == "__main__" for Python Developers
8:47
Просмотров 401 тыс.