NO ONE Taught You THIS About Type Hinting In Python 👑

preview_player
Показать описание
This is a game changer for type hinting in #Python. #Shorts
Рекомендации по теме
Комментарии
Автор

“When you’ve been coding in C for your whole career and your boss forces you to make an application in python”:

Flameandfireclan
Автор

I have used a lot of typehinting in my projects before, but I have never used a pipeline or the ellipses! Thanks this taught me a alot!

elirol
Автор

Tuples are immutable so you shouldn't be varying their length. You'll notice your editor won't complain if you define a list e.g. my_list: List[int] and put any number of ints into the list.

LittlePharma
Автор

That first one is something i wish i knew 5 years ago when i was re writing a game client.

Автор

i never used ellipses yet but damn once i finish the general projects i'm gonna dive into that!

GamingAbroad
Автор

That’s actually really useful! Thanks for sharing!

greyhat_gaming
Автор

The point of the tuple is for you to define the shape. By doing a rest + union data type you're just trading correctness for "annoying"

Michael-rcks
Автор

In usage, tuples are closer to dictionaries or (data)objects than to lists. A tuple typically represents some entity with differently typed values (like attributes). This becomes especially clear if you look at things like named tuples.

SaniSensei
Автор

Dude these videos are SO good. Love these little sub minute tips.

viatori
Автор

I have been seeing this ellipses when reading API documentation sometimes but never got curious enough to search about it. I have used all other type hints except the tuple so this is actually helpful, thank you.

Isaglish
Автор

You are 100% correct no one taught me this.i myself learned it way before.

eftehassan
Автор

When C Dev's start coding in python 🤣🤣

ShivanshKaran
Автор

I could see wanting to use a tuple like a list like this because they’re immutable… but that’s it! Normally tuples are just 2 values

Joshua-spkd
Автор

Congratulations, you just created an int array... Tuple should have a definitive number of properties, otherwise what is the point of even having them....

RipazX
Автор

but a tuple should always be the same length so the way to fix this is use a

TheAndiKurz
Автор

Python slowly that read like human language marketing

cabbage-dev
Автор

Thats not what tuples should be used for. At this point just use a list[t].

cn-ml
Автор

I feel it should be double asterisk instead of ellipsis. Like [**int]

RyanBarnes
Автор

I can see the argument about using the ellipsis as a shorthand for having repeated types, but as soon as you add that union, that starts screaming that need to use something else than a tuple (like a list) unless you definetely know your type has to be a tuple.

The whole point of tuple is to have typed collections of specific lengths and possibly heterogenous types, that are immutable, and that have the precision to tell which item has what type.

thetos
Автор

Great videos. Can you make one on the: variable: type = x notation? First time I've seen this!

vassili