Python 101: Learn These 5 Must-Know HIDDEN Features

preview_player
Показать описание
To learn programming and Python - check out Datacamp!

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 🎓

🎓 Free Courses 🎓

⏳ 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 🔗

🔗 Support 🔗

🔖 Tags 🔖
- Python Beginner Tutorial
- How To Code Using Python
- Python Tips & Tricks

Hashtags
#techwithtim
#pythonprogramming
#softwareengineer
Рекомендации по теме
Комментарии
Автор

To learn programming and Python - check out Datacamp!

TechWithTim
Автор

- 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

ReflectionOcean
Автор

The default value function in a defaultdict is a good place to use a lambda function.

logaspam
Автор

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.

swolekhine
Автор

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

FigmentariumAnimation
Автор

In the last example we can alternatively use the dict idiom char_count[char] = char_count.get(char, 0) + 1

fghhna
Автор

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)

Casey_W
Автор

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

patrickprucha
Автор

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.

tacobuddy
Автор

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. 🙌🏻

usamashami
Автор

Athough I know some of the features, I love this video. Useful. Thanks.😁😁😁

davidlu
Автор

Great explanation of the usefulness of the walrus operator, all became clear. Thanks.

BrianSwatton
Автор

16:12 why not use Counter from collection for this case ;) ?

stevengorlich
Автор

I enjoyed our video as I learned several Python features of which I was unfamiliar.

bevintx
Автор

*Hi Tim! Am new subscriber. Thank you for sharing about these 5 must know hidden features! 🍁🌿*

isalutfi
Автор

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

letsRegulateSociopaths
Автор

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

comproprasad
Автор

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
```

valorien
Автор

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}

DrDeuteron
Автор

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.

jaylooppworld