这些都是等效的(调用者不必更改):
# 2.x unpacks tuple as part of the function call, 3.x raises exception
def get_year((year,prefix,index,suffix)):
"""get year from (year, prefix, index, suffix) tuple"""
return year
# 2.x and 3.x, you unpack tuple in the function call
def get_year(year_tuple):
"""get year from (year, prefix, index, suffix) tuple"""
year, prefix, index, suffix = year_tuple
return year
# 2.x and 3.x, speedier because you don't unpack what you don't need
def get_year(year_tuple):
"""get year from (year, prefix, index, suffix) tuple"""
return year_tuple[0]