Underscores Can Do What?! #python #programming #coding

preview_player
Показать описание
This short video shows you 3 helpful tips using underscores in Python!

Background Music:
Attribution 4.0 International (CC BY 4.0)
Рекомендации по теме
Комментарии
Автор

Note that because both are based on conventions, you cannot combine tip 2 and 3: As long as a global variable called _ is defined, the interactive prompt does *not* overwrite it with the last result. You can either unassign it (del _) or use a different name like "_unused" to restore that behavior.

DSamp
Автор

That's really cool! I'll be using these!

theminecommander
Автор

I didnt know the 3rd thats a game changer

GamingAbroad
Автор

Did not knew these. The underscore with numbers will be a game changer for me

prod_joel.
Автор

Thank. Nice video. I am always surprised how useful separating digits with underscore can be. However I haven't had chance to see it in real code.

lukaschumchal
Автор

# Tip 1.1 Improve the readability of large printed numbers:

>>>print(f"{c:_}")
299_792_458

open
Автор

The second method is called a "discard variable". It does exist in C# as well and (opposed to other variables in C#) does not need to be defined.

As a side note, defining the age AND the year of birth is often questionable design, unless you explicitly need both values all the time :D In most cases giving the exact birth date is better when possible.

NFSHeld
Автор

The 2nd method is especially useful when you're tuple unpacking dictionaries.

Iam_Qachal
Автор

Lua also uses throwaway underscores btw

bakedgiraffe
Автор

Tip number 1 was unknown to me. Thx a lot

fabiosoares
Автор

All of these except the 3rd apply in Swift as well if anybody’s learning that

beclops
Автор

U forgot one more which is using two _ before private method names

jeffery_tang
Автор

for _ in range(x). If variable is not needed.

WSpe
Автор

I tested that second one also works in Lua

ThisIsEndlessVoid
Автор

Super useful! Btw what font are you using?

BlueSheep
Автор

I trust nobody that would write 2_000 instead of 2000

RealQuarlie
Автор

Have you maded a video on why Binary has 0b, hex has 0X similary with Octal?!

shikharmishra
Автор

One that was missed here is that members of a module that start with an underscore, are not imported when you import * from a module.

That makes variables that start with an underscore "private" in some sense

PattyManatty
Автор

How is the last taking 0.3 seconds? That’s long enough to actually slow you down

codaaaaaaaaa
Автор

til you can use the unpacking operator in the middle

_Elvyra._