Python is currently the most used programming language in the world, and the unique reason is that Python developers are happy building software wi...
For further actions, you may consider blocking this person and/or reporting abuse
Unpacking gets even better than that...
You can include one starred name among the names to unpack into. Python will fill in all the others based on position, and then stuff the rest into the starred name.
In this case, I use
_
for the name, because I really only intend to throw those away._
is a completely valid name in Python, but it's conventionally used as a "throw away" name. If you're curious, you can still see what was parked in there in the above code with...P.S. Bit of shameless self-promotion, all of the above is in my forthcoming book "Dead Simple Python" (No Starch Press, 2021). So, it isn't quite that "no one" covers this stuff.
What such an amazing explanation Jason.🤯
That's exactly why I said the unpack operator deserves an isolated article.
BTW, I'd be glad to read your book.
If you want, you can add directly here the link 😉
Heh, I will once I have one. It'll be this fall, tho.
Sweet, man! I didn't even know these existed!!
The * python iterator is kind of like the ES6
[...arr]
in a way.Hey! I think I know you ...
It seems Python and Js are not that different 🤣
Wow, that is a really great post though! I am very surprised by those tricks and tips actually, as I did not even expect that you can do this kind of things. And, that is true, no one actually teaches you those things, which makes them even more amazing! I am learning python right now actually, and I have to tell you that most of the teachers tend to avoid from teaching us different useful tips and tricks, the only place where you could actually find these tricks are the python learning websites, nurtem.com/classes-and-camps/progr... is one of them, and probably the best one, at least the best ones.
fantastic article! i learnt many things new
Thanks for the feedback 🙏
Nice! Some neat tips in here.
Thanks 🙏🏼
Great knowledge shared.. Keep up the good work
I'm glad you find it useful!
Amazing article keep it up
You can use
some_list.reverse()
also
Of course. That is a useful method,