this post was submitted on 01 Mar 2025
20 points (88.5% liked)
Programming
18472 readers
118 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
Functions in Python can only return a single value. While you are allowed to comma-separate additional values, as you have done, they are combined into a single tuple object that wraps the intended values.
As such, your splitter function is returning a single tuple containing three strings. Your calculate function is expecting three individual arguments (I'm guessing that the error trace mentions this).
To get around this, you can use the splat/asterisk operator to "unpack" the items from the tuple:
Edit: removed bad asterisk
that's not ~~true~~ accurate, this is valid code in this context:
Where x, y, and z are strings. But when you do this, akin to what OP did:
then
value
is a tuple of 3 strings.In fact, unpacking with asterisk at assignment, like below, is not allowed:
Gahh, serves me right for blindly writing code on my phone!