How Did I Not Know THIS About Python Before?

preview_player
Показать описание
How did I not know this about Python before? #python #code #shorts
Рекомендации по теме
Комментарии
Автор

fun fact: you can also do this:
a, (b, c), *d, e = [0, [1, 2], 3, 4, 5, 6]
you can unpack inner lists too, and you can use the * to unpack all in the middle, so a is first, (b, c) is second, and e is the last value

Visually:
a = 0
b = 1
c = 2
d = [3, 4, 5]
e = 6

welcome to the pythonic headaches

ProfRoxas
Автор

Yeah, seriously. Why would you not know this?

엄랭
Автор

Yeah dude, not knowing things that come on the first pages of every python course is kind of embarrasing

konstantin
Автор

"how did I not know this about python?" shows the most basic python thing

Gabryx_
Автор

Wait, do y'all don't know tuple unpacking?

AkivaB
Автор

You can also unpack values at specific Indexes:

t = 1, 2, 3, 4, 5, 6
a, _, _, b, c, d = t


for example.

xCwieCHRISx
Автор

You can also use the *operator if you need just a few selected elements
tuple_a = ("Morning", "Afternoon", "Evening", "Night")
and you want only Morning and Night
Then let's say a, *b, c = tuple_a

a = "Morning"
b = ["Afternoon", "Evening"]
c = "Night"

CountryCalledCHAD
Автор

ppl: "How did I not know this" is a rhetorical introduction.,

DrDeuteron
Автор

can we borrow descriptivism from linguistics please?

supereric
Автор

What do you mean I learn from you and then you say you don't know the 1st thing about tuples?

humanrightsadvocate
Автор

Well what if I have a dynamic tuple that change number of elements each time 🙂 how can you know the numbers of variables for each elements if you dont know the number in advance

aminegatou
Автор

As well, you can put everything in a single line.
a, b, c = (1, "aiiinnn", 2.0)

pandasoli
Автор

Yeah why didn't you know about this?

comedyclub
Автор

Also known as array destructuring in JavaScript world 🌍

richardjamesbunker
Автор

"how to split a large array into three variables" make this

kite
Автор

it's difficult to answer how you did not know that.

ytlongbeach
Автор

for i in a:
print(i, end=" ")
🙃

garip_biri
Автор

Because you were an empty string before .😂

eftehassan
Автор

i actually knew about this when i was first starting python, because i barley knew i needed to get the tuple elements into variables, and i searcehd on google and found this, i didnt even know about indexing

Zhaxxy
Автор

it's right, it's not the best way, that's it

jvcss