this post was submitted on 01 Mar 2025
20 points (88.5% liked)
Programming
18472 readers
268 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities [email protected]
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Change this:
to this:
The error is that
calculate
expects three float values (x
, andy
, andz
), butsplitter
returns a tuple object ((x, y, z)
as one object, similar to arrays in other languages):Prepending a tuple or a list with a
*
operator (unpacking or splatting) unpacks the object into its individual items that are then passed to the function as separate arguments.In fact,
str.split()
already returns a tuple. By assigning multiple values at once inx, y, z = expression.split()
, you actually unpack the returned tuple into individual values, then inreturn x, y, z
, you pack those values into a tuple.