Unpacking With Asterisk Operators in Python

Unpacking With Asterisk Operators in Python

Real Python

4 года назад

11,985 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Marcos Mercado
Marcos Mercado - 09.10.2023 21:51

Great video, thanks! Question: Is it possible to unpack the iterable and, at the same time, apply a function to each of the unpacked elements? For example, I have a list of strings that have trailing whitespaces that I want removed. I was thinking of calling the strip() method on each element as the list is unpacked. I tried different ways but I was not successful, so I ended up using list comprehension. Is something like this possible with the unpacking operator?

Ответить
pawjast
pawjast - 12.01.2023 15:20

Short but useful!

Ответить
Tyler Durham
Tyler Durham - 22.06.2022 19:23

Thank you! This makes a little more sense now and my brain broke slightly.

Ответить
Keifer
Keifer - 11.06.2022 04:27

This was a great video. Amazing explanation

Ответить
r m
r m - 12.02.2022 02:39

I have good knowledge of python and am completely confused.

Ответить
Alamin Bijoy
Alamin Bijoy - 04.07.2021 23:36

Note: basically asterisk(*) operator is the default way of merging two iterables

Ответить
Alireza Akhavi
Alireza Akhavi - 30.03.2021 16:49

thank you very much for your great content! :) very interesting and clear

Ответить
Lilahxxxx
Lilahxxxx - 23.12.2020 00:33

Thank you very much!!

Ответить
Yoni Ziv
Yoni Ziv - 14.10.2020 13:17

Thank you for this clear explanation!

Ответить
Django Lessons
Django Lessons - 12.01.2020 14:29

good explanation. Thank you! What video editing program you use ?

Ответить
adnan kaya
adnan kaya - 10.01.2020 09:30

Well explained! Thank you.

Ответить
Kiran Reddy
Kiran Reddy - 10.01.2020 07:41

Hey Dan
At first i didn't understand the trick (merging two dictionaries) that appears on your real python website .
But now it's crystal clear
Thank you Dan barder
Expecting more such tricks from real python team .

Ответить
Aashay Amballi
Aashay Amballi - 10.01.2020 06:14

Thank you, that was helpful... 😊

Ответить
Cătălin George Feștilă
Cătălin George Feștilă - 10.01.2020 00:51

good video tutorial:

>>> *a, = "RealPython"
>>> print(*a)
R e a l P y t h o n
>>> print(a)

['R', 'e', 'a', 'l', 'P', 'y', 't', 'h', 'o', 'n']
>>> zeros = (0,) * 8
>>> print(zeros)
(0, 0, 0, 0, 0, 0, 0, 0)
>>> *a,
('R', 'e', 'a', 'l', 'P', 'y', 't', 'h', 'o', 'n')
>>> *c, b = a
>>> *c,
('R', 'e', 'a', 'l', 'P', 'y', 't', 'h', 'o')

Ответить
Devenger Hack
Devenger Hack - 09.01.2020 21:16

Nice

Ответить
praneet nigam
praneet nigam - 09.01.2020 21:09

Want to start learning machine learning, data science or AI and looking for good resources. Start learning from top industry experts bloggers, articles, books and video lectures in one place on OpenAcademy. Find on Google PlayStore.

Ответить