Why tuples use parentheses ()'s instead of something else like <>'s?

Leif K-Brooks eurleif at ecritters.biz
Wed Dec 29 01:37:45 EST 2004


seberino at spawar.navy.mil wrote:
> Wouldn't it have been better to define tuples with <>'s or {}'s or
> something else to avoid this confusion??

The way I see it, tuples are just a way of having a function return 
multiple values at once. When you think of them that way, you don't even 
need parenthesis:

def foo():
     if we_found_stuff:
         return 200, 'long and boring result'
     else:
         return 404, 'nothing found'

status_code, body = foo()

If foo() only needed to return one value, it would do so in the normal 
way, and you wouldn't need to worry about 1-tuples.



More information about the Python-list mailing list