def handleargs(arglist):
"""Take list of arguments and extract/create proper start, stop, and step
values and return in a tuple"""
try:
if len(arglist) == 1:
return 0, int(arglist[0]), 1
elif len(arglist) == 2:
return int(arglist[0]), int(arglist[1]), 1
elif len(arglist) == 3:
if arglist[2] == 0:
raise ValueError("step argument must not be zero")
return tuple(int(x) for x in arglist)
else:
raise TypeError("range() accepts 1-3 arguments, given", len(arglist))
except TypeError:
raise TypeError("range() arguments must be numbers or strings "
"representing numbers")
评论列表
文章目录