Python 101: Learn These 5 Must-Know HIDDEN Features

  Рет қаралды 65,675

Tech With Tim

Tech With Tim

Күн бұрын

Become a professional softwate developer as quickly as possible: techwithtim.net/dev
Python is a fascinating programming language that contains a lot of hidden & extremely useful features. In this video, I will be showing you 5 of these features that you need to understand if you want to fully grasp the language.
🎓 Premium Courses 🎓
🏢 CourseCareers - techwithtim.net/dev
🔗 BlockchainExpert - algoexpert.io/blockchain (use code “tim”)
💻 ProgrammingExpert - programmingexpert.io/tim (use code “tim”)
🎓 Free Courses 🎓
📚 Introduction To Software Development: techwithtim.net/dev
⏳ Timestamps ⏳
00:00 | Python 101
00:28 | Anonymous Variable
02:54 | For/While Else
05:24 | Become A Software Developer
06:20 | Walrus Operator (:=)
09:57 | Argument Unpacking
13:18 | Default Dictionary
🔗 Socials 🔗
📸 Instagram - / tech_with_tim
🐦 Twitter - / techwithtimm
💬 Discord - / discord
🤝 LinkedIn - / tim-ruscica-82631b179
🌐 Website - techwithtim.net
💾 GitHub - github.com/techwithtim
🔗 Support 🔗
👕 Merch - teespring.com/stores/tech-wit...
💵 Donations - www.paypal.com/donate?hosted_...
🙏 Patreon - / techwithtim
🔖 Tags 🔖
- Python Beginner Tutorial
- How To Code Using Python
- Python Tips & Tricks
Hashtags
#techwithtim
#pythonprogramming
#softwareengineer

Пікірлер: 102
@TechWithTim
@TechWithTim 3 ай бұрын
Want to landed an $80k developer job in 2024? Check out the CourseCareers Software Development program: techwithtim.net/dev
@dmytro_dexter
@dmytro_dexter 3 ай бұрын
Where is the guarantee that this announce about job is not just an empty words?
@ayojoy1443
@ayojoy1443 3 ай бұрын
Tim I tried to email you about your course. Your email on your website doesn't work
@TechWithTim
@TechWithTim 3 ай бұрын
We just had a student graduate and land a job in 3 weeks! Obviously we cannot guarantee a job but we’ve tailored the program specifically with that goal in mind.
@TechWithTim
@TechWithTim 3 ай бұрын
send it to techwithtimm@viralnationtalent.com@@ayojoy1443
@dmytro_dexter
@dmytro_dexter 3 ай бұрын
@@TechWithTimwhere can I check the agenda of the course? What are going to teach on this course?
@logaspam
@logaspam 3 ай бұрын
The default value function in a defaultdict is a good place to use a lambda function.
@aflous
@aflous 3 ай бұрын
No need, can simply use int
@logaspam
@logaspam 3 ай бұрын
​@@aflous if it's that simple, yes, but if there is more logic involved then the lambda function allows you to see it in the defaultdict rather than having to look at a separate function.
@aflous
@aflous 3 ай бұрын
@@logaspam for sure yeah, I was answering regarding the example in the video. But I agree lambda makes much more sens here, but would only work if it can be written as a single statement
@DrDeuteron
@DrDeuteron Ай бұрын
@@aflous I wrote lambda (single statement) that computed the partitions of an integer, so you can get pretty sick.
@swolekhine
@swolekhine 3 ай бұрын
I was amazed at how much uproar the walrus operator caused when it arrived in Python 3.8. Your list comprehension example with the f(x) assignment is a clear use case that isn't possible (at least without something really convoluted) without it.
@themartdog
@themartdog 3 ай бұрын
I agree, I've never cared much for walrus but seeing that example was a "duh" moment for me in understanding an awesome use for it
@edwardcullen1739
@edwardcullen1739 3 ай бұрын
A common problem in C languages is someone doing: while (x = my_func(y)) ... instead of: while (x == my_func(y)) ... Which have very different meanings. Python _avoided_ this problem by explicitly prohibiting assignment in conditional context. The issue is you end up with people forgetting to update the evaluation variable at the end of the loop. By introducing an explicit assignment syntax that's "safe" for use in conditionals, you solve both problems. Those objecting likely didn't understand the cause/effect or had just bought the dogmatic "thou shalt not assign in an iterator expression" and we're being dogmatic.
@fghhna
@fghhna 3 ай бұрын
In the last example we can alternatively use the dict idiom char_count[char] = char_count.get(char, 0) + 1
@Casey_W
@Casey_W 3 ай бұрын
There is nothing particularly "anonymous" about the "_" variable; it is simply a variable named "_" that is anonymous by convention (you could also use "__", "___", etc). This is also used by convention in classes to designate private variables/methods (preceded by a single underscore) or special variables/methods (preceded and concluded with double underscores, the so-called "dunder" methods). Also, in your first walrus generation example it works fine, but better python code would be to have the generator simply yield the results (no "-1" sentinel value) and then for loop over it: def gen_data(): for i in range(10): yield i gen = gen_data() for i in gen: print(i)
@justpochta
@justpochta 2 ай бұрын
Agree. There is no need to try anonymize variables at all.
@tsebllort5423
@tsebllort5423 2 ай бұрын
It points out to other dev reading your code that your variable is not intended to be used.
@usamashami11
@usamashami11 3 ай бұрын
Wow this video is really insightful! ❤ Walrus operator is new for me, so is the defaultdict! And I always wondered what those asterisks in f(*args, **kwargs)are. Today it made some sense, as they are unpack, double unpack operators! Everytime I see your video, I get to know about something unique. Thanks and keep it up. 🙌🏻
@user-vi1tw1xw7r
@user-vi1tw1xw7r 3 ай бұрын
Great explanation of the usefulness of the walrus operator, all became clear. Thanks.
@Dubs3
@Dubs3 3 ай бұрын
@TechWithtTim what key caps do you use? I love the sound
@figmentariumanimation7598
@figmentariumanimation7598 2 ай бұрын
I’ve been learning coding for six months but I can say that your channel is the one that made me start to really love it. Thank you my man
@bevintx5440
@bevintx5440 3 ай бұрын
I enjoyed our video as I learned several Python features of which I was unfamiliar.
@patrickprucha5522
@patrickprucha5522 2 ай бұрын
Hey Tim. Thanks for your inspiration. I wanted to share a little thing that i just discovered. I'm starting python. I was doing bash scripting for carrying out my maintenance and other stuff. I found when bash scripting, i was able to try out the commands on the command line. I just found that using python's command line interface, i can start to understand the different aspects of python. In my case, i find this a fantastic approach, especially if i have to use the sys or os modules (which i will read up in the near future) and start using the commands with pythons data structures. I bring this up as an alternative to jumping and writing a program (I'm a old dude that needs a purpose to program, and have completed many projects in my career and different positions). This approach allows one to get familiar with python and test out some syntax requirements with python. I believe for bash scripters, it may be a good bridge to cross between bash and python. Thanks again! Cheers
@tacobuddy7258
@tacobuddy7258 3 ай бұрын
The int function can also be used in the defaultdict parameter. When you don't pass an argument to int(), by default it will return a 0.
@ReflectionOcean
@ReflectionOcean 3 ай бұрын
- Utilize the underscore as a placeholder when declaring variables you do not intend to use to avoid syntax errors and clear confusion about the variable's role. 0:29 - Implement the 'else' statement with 'for' and 'while' loops to execute a block of code when the loop is not terminated by a 'break' statement, simplifying the need for flag variables. 3:00 - Explore the walrus operator (:=) in Python 3.8 for defining a value as part of a condition in loops, making code more readable and efficient. 6:22 - Apply argument and parameter unpacking using the asterisk (*) and double asterisk (**) operators for passing multiple arguments or keyword arguments from iterables or dictionaries to functions, enhancing code readability. 10:00 - Use the default dictionary from the collections module to automatically assign default values when accessing keys that do not exist, streamlining code that increments keys or processes missing keys. 13:20
@lukekurlandski7653
@lukekurlandski7653 3 ай бұрын
#2 is rarely a good idea imo because its difficult to remember the semantics of this construct.
@MichielvanderBlonk
@MichielvanderBlonk 2 ай бұрын
​@lukekurlandski7653 true. I also don't use it because it makes my code look wrongly indented when there is an if inside my loop.
@farzadmf
@farzadmf 3 ай бұрын
You could also do defaultdict(int)
@allxalone
@allxalone 3 ай бұрын
we could also use char_count=char_count.get(char,0)+1 instead of the defaultdict or is there any other advantage to it other than code readability and conciseness
@ryanonism
@ryanonism 3 ай бұрын
For this scenario .get() works fine, but let's say you want to have a list as your default value. And you want to append something, now you just use char_list[char].append(i) without having to initialize the list. Edit: upon some testing. It seems you can achieve the same with .get() it just gets messy when you start having nested data structures. So yeah I guess defaultdict is just to be clean, as far as I can tell.
@makingachanneltopost
@makingachanneltopost 12 күн бұрын
That was pretty much my go-to method before I started using collections.defaultdict
@isalutfi
@isalutfi 3 ай бұрын
*Hi Tim! Am new subscriber. Thank you for sharing about these 5 must know hidden features! 🍁🌿*
@TechWithTim
@TechWithTim 3 ай бұрын
Thanks for being a new sub!!
@head0fmob
@head0fmob 3 ай бұрын
great list Tim
@stevengorlich4993
@stevengorlich4993 2 ай бұрын
16:12 why not use Counter from collection for this case ;) ?
@davidlu1003
@davidlu1003 2 ай бұрын
Athough I know some of the features, I love this video. Useful. Thanks.😁😁😁
@loosabway3400
@loosabway3400 3 ай бұрын
Love your hallway!
@valorien1
@valorien1 2 ай бұрын
When using Defaultdict to count something, there's no need to define a special default function that returns 0. You can use the built in `int()` function (which returns 0 by default) like so: ``` d = Defaultdict(int) for i in some_iterable: d[i] += 1 ```
@alexanderkomanov4151
@alexanderkomanov4151 3 ай бұрын
Good tips!
@user-xk6rg7nh8y
@user-xk6rg7nh8y 3 ай бұрын
very well organized :)) And thank you so much to let me know this cute expression :=
@lapispheonix7569
@lapispheonix7569 Ай бұрын
for the char_count, you dont need a whole function for it, you can use a lambda: char_count = defaultdict(lambda: 0)
@makingachanneltopost
@makingachanneltopost 12 күн бұрын
Worth noting that for defaultdict, instead of calling your handmade function "default" you could have done the same thing by saying: char_count = defaultdict(int)
@DrDeuteron
@DrDeuteron Ай бұрын
regarding the defaultdict ofc it's awesome, but the "counter" example is explanatory, but problematic, since: collections.Counter does it already ;-) ....and you will use it in your code: >>>Counter("abbccc") {a: 1, b: 2, c: 3}
@edwardcullen1739
@edwardcullen1739 3 ай бұрын
The while...else syntax makes me queasy. But then, breaking from loops makes me queasy too 🤷‍♂️ (Consider: I have a very specific set of experiences... 😅)
@comproprasad6438
@comproprasad6438 3 ай бұрын
result = [f(x) for x in range(10) if f(x) > 3] Alternative 1: result = [x for x in (f(i) for i in range(10)) if x > 3] Alternative 2: result = (f(i) for i in range(10)) result = [x for x in result if x > 3] Both alternatives are more efficient than the original one
@user-uh1yf2fd1e
@user-uh1yf2fd1e 3 ай бұрын
thank you very much.
@Ryan-Fkrepublicnz
@Ryan-Fkrepublicnz 2 ай бұрын
at 5:00 it is confusing for you to leave the i variable code for beginners like me. I really couldn't get why it was there, then I realized you just didn't remove it
@rancio3354
@rancio3354 20 күн бұрын
I use defaultdict and pass list as argument then just append stuff to the key something like d = defaultdict(list) d[key].append(“item”)
@hubijohn7451
@hubijohn7451 3 ай бұрын
Great stuff
@TheAwaeng
@TheAwaeng 3 ай бұрын
The walrus operator is much appreciated in Machine Learning !!
@jaylooppworld381
@jaylooppworld381 3 ай бұрын
Crazy how i know everything he mentioned here and i still don’t consider myself a professional pythonista. And i learned all this on my first year with python. Anyway i recommend people to learn more from books, it is the only way to get all the knowledge with very few gaps, not knowing this that he talk about in the video after 3 years of coding with python really impressed me, taking in account that Tims likes learning more with books. I assume he just focused on subjects that matter to him, and probably skipped those subjects on his earlier stages learning python.
@DrDeuteron
@DrDeuteron Ай бұрын
omg, I can help it. for star magic: >>>numbers = print >>>numbers(*lst) I know, it was a toy example.
@rickkenny5342
@rickkenny5342 3 ай бұрын
Thanks!
@TechWithTim
@TechWithTim 3 ай бұрын
Wow thank you!
@ventin75
@ventin75 3 ай бұрын
I would use this instead of For/While Else. items =["a", "b", "c", "d"] if "z" in items: print("yes") else: print("No")
@lxathu
@lxathu 3 ай бұрын
With walrus, we finally have what we always had in C just turning the meaning of the symbols upside down, a little like if we mixed Pascal and C to have Python but leaving hardly anything at its original place.
@henryyoung7184
@henryyoung7184 2 ай бұрын
You mean asterisk rather than asterix. The latter is a French comic character from Asterix The Gaul
@CedricThePlaystation
@CedricThePlaystation 3 ай бұрын
I also love that Swift has some of these features as well, albeit with different syntax.
@Codecrafters_hub-
@Codecrafters_hub- 3 ай бұрын
you are close to1000 vids. you can do it✌
@DrDeuteron
@DrDeuteron Ай бұрын
for grabbing the second element of a list of containers, I kinda like: >>>second = list(map(itertools.itemgetter(2), list_of_containers))
@17crescent
@17crescent 3 ай бұрын
I would use char_count = defaultdict(int)
@user-ck9tb4fv2x
@user-ck9tb4fv2x 11 күн бұрын
Anonymous Variable. Uh You just named the variable underscore instead of whatever else you where gonna name it. ** unpack is cool but the example is funny because you change the args that are passed through but the print statement is still print(key, value) so the idea changing the function parse_values would do anything is a lil silly but the *, and ** unpacking is cool. I also Like the other ones listed. default dictionary is awesome, walrus operator is gonna take a second but the concept is cool. For/While else. Yea I mean I guess I just didn't think to do that why not.
@joelneely
@joelneely 3 ай бұрын
“Asterix” is a cartoon character; “asterisk” is a star-shaped special character.
@Big_chicken-ok8gc
@Big_chicken-ok8gc 3 ай бұрын
Tim I greatly appreciate what you teach and do but python Is getting a bit repetitive. I love python, it's great. It's my go-to language. but I would definitely like to see some other languages or other tech based topics on this channel. I'm also saying this because in your recent videos almost all your latest videos have pythons logo in the thumbnail lol. Still, love your work, love what you teach, keep it up. ❤️ ❤️
@TechWithTim
@TechWithTim 3 ай бұрын
Thanks for the feedback I’ll definitely keep it in mind! What languages do you want to see?
@Big_chicken-ok8gc
@Big_chicken-ok8gc 3 ай бұрын
@@TechWithTim i would really appreciate a video about C, js or maybe some front-end content. Thanks for listening!
@jaylooppworld381
@jaylooppworld381 3 ай бұрын
This comment is senseless, if you want to see C coding videos, isn’t it better to search for a channel that is mainly about C programming? Instead of trying to find it in a python programming channel?
@Big_chicken-ok8gc
@Big_chicken-ok8gc 3 ай бұрын
@@jaylooppworld381 Tim dosent code every video in python and he does sometimes use other languages. And what if there are other videos on C? I like Tims way of explaining programs so that's why I asked him. He dosent HAVE to create a video just because a random guy said make a C video. But I just gave a few examples of which languages I wanted to see on the channel.
@amingaming6754
@amingaming6754 3 ай бұрын
What sorts of jobs I can do with just python in freelancing. Please mention some of it
@jonahsatheesh5346
@jonahsatheesh5346 3 ай бұрын
Could you make a tutorial on hosting an llm from hugging face onto a free server or domain? Including how make a ui for it Pleaseee
@chrisw1462
@chrisw1462 Ай бұрын
That last one seems a little esoteric. Is it really used much?
@SkyTiger86
@SkyTiger86 3 ай бұрын
BEST
@lbalcerzak
@lbalcerzak 2 ай бұрын
please do not use that for/while else syntax. It's cool when you see it for the first time. But you forget how it works day later (usually people think "else" section executes if iterable is empty which is not the case).
@Artifactorfiction
@Artifactorfiction 3 ай бұрын
I hate the else after the while … This just doesn’t make the code more readable … I guess “if break:” or “if not break:” would be more readable and more noticeable to any future maintainer who may add more break related logic to the loop … maybe I’m getting too old … bah humbug …
@epotnwarlock
@epotnwarlock 3 ай бұрын
How would you get to the if break? I feel like you would have create another variable
@1CProgrammer
@1CProgrammer 3 ай бұрын
Thumbnail just saying me please learn python, Me: ok
@karserasl
@karserasl 3 ай бұрын
DO NOT USE FOR/ELSE The founder of python said that it was his biggest mistake to allow this to be added to python
@JJ-SH
@JJ-SH 3 ай бұрын
Literally none of those are hidden features. Walrus makes code less readable and more complex (not complicated) for no benefit whatever. Similarly for/else is notoriously difficult to read without a double take to understand what's going on, although it adnitedly does have it's niche uses on occasion.
@TechWithTim
@TechWithTim 3 ай бұрын
Did you look at the walrus use cases I presented, often times you can increase code efficiency
@ag.cousins
@ag.cousins 3 ай бұрын
Do Canadians say “zed” instead of “Zee”?
@martijnb5887
@martijnb5887 3 ай бұрын
No, Americans say "Zee" instead of "Zed".
@ironfbody
@ironfbody 3 ай бұрын
The very fact that these features are HIDDEN, means the code is harder to read.
@samuelcarlos4234
@samuelcarlos4234 Ай бұрын
This for/while else is a dumb way of doing that. You can just use if 'item' in items, else
@olukayodepaul7070
@olukayodepaul7070 3 ай бұрын
all available in kotlin....
@unsuspicious_youtuber
@unsuspicious_youtuber 3 ай бұрын
I heard "python is a fas" And my brain instantly thought he was going to say fast. I was like okkkkkk yeeaaeah... right... fast 😂
@baconsledge
@baconsledge 3 ай бұрын
Wahhhh! There are plenty of embedded jobs for real programmers.
@ButchCassidyAndSundanceKid
@ButchCassidyAndSundanceKid 3 ай бұрын
There're no more IT jobs on the market, so it's pointless to go onto any of the training courses.
@TotallyNotAuroras2ndChannel
@TotallyNotAuroras2ndChannel 3 ай бұрын
All the indians are stealing our jobs
@alchimyst4995
@alchimyst4995 3 ай бұрын
What on earth are you talking about? If you can't find a job as a field tech/ tech hand due to your local market, specialization in a field will allow you to market yourself to specialized fields. Growing in your specialization will require fundamentals such as the ones offered on the cert sites you mention. If you don't understand TCP/IP, Subnetting, Protocols, Security Configuration, etc... you should worry about that before concerning yourself with the status of the job market. This is invaluable knowledge in our society where every company and organization is fundamentals reliant upon these technologies. The people that built them will die one day, if everyone had your attitude we wouldn't have anyone to support those systems.
@ButchCassidyAndSundanceKid
@ButchCassidyAndSundanceKid 3 ай бұрын
@@alchimyst4995 Which planet have you been living in the last 2 years ? Companies have been laying off staff in droves. Even on youtube here you can find oodles of videos that tell of mass layoffs by their employers and the sorry state of the tech sector.
@scottmays8507
@scottmays8507 2 ай бұрын
No, he's right.
@RobertSmith-lh6hg
@RobertSmith-lh6hg 2 ай бұрын
LOL. Interesting that I just got hired like 2 weeks ago...
@TKZ9
@TKZ9 3 ай бұрын
PLEASE DO A TUTORIAL ON FLET LIBRARY🥲
Python Generators Explained
28:37
Tech With Tim
Рет қаралды 140 М.
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1 МЛН
船长被天使剪成光头了?#天使 #小丑 #超人不会飞
00:28
超人不会飞
Рет қаралды 26 МЛН
АВДА КЕДАВРАААААА😂
00:11
Romanov BY
Рет қаралды 10 МЛН
NixOS Tutorial - NixOS Modules
10:04
Why Does Nothing Work
Рет қаралды 82
Python's 5 Worst Features
19:44
Indently
Рет қаралды 45 М.
10 Python Shortcuts You Need To Know
27:27
Tech With Tim
Рет қаралды 289 М.
10 Python Comprehensions You SHOULD Be Using
21:35
Tech With Tim
Рет қаралды 85 М.
10 ULTIMATE Python Tips 🔥
16:42
Tech With Tim
Рет қаралды 58 М.
5 Signs of an Inexperienced Self-Taught Developer (and how to fix)
8:40
5 Good Python Habits
17:35
Indently
Рет қаралды 273 М.
Write Python Code Properly!
25:46
Tech With Tim
Рет қаралды 139 М.
5 Uncommon Python Features I Love
15:09
Indently
Рет қаралды 114 М.
I've Read Over 100 Books on Python. Here are the Top 3
9:26
Python Programmer
Рет қаралды 240 М.