您好,欢迎来到上海分类信息网
免费发信息

Python编程入门之函数可变参数

2024-4-10 8:36:14发布11次查看ip:发布人:
finally, the least frequently used option is to specify that a function can be called with an arbitrary number of arguments. these arguments will be wrapped up in a tuple (see tuples and sequences). before the variable number of arguments, zero or more normal arguments may occur.最后,最不常用的选项是指定函数可以用任意数量的参数来调用。这些参数将被封装在一个元组中(参见tuples和序列)。在变量数目可变之前,可能出现零个或多个正常参数。
defwrite_multiple_items(file,separator,*args):file.write(separator.join(args))
normally, these variadic arguments will be last in the list of formal parameters, because they scoop up all remaining input arguments that are passed to the function. any formal parameters which occur after the *args parameter are ‘keyword-only’ arguments, meaning that they can only be used as keywords rather than positional arguments.通常,这些变量参数将在正式参数列表中最后一个,因为它们获取传递给函数的所有剩余输入参数。在*args参数之后出现的任何正式参数都是“仅关键字”参数,这意味着它们只能用作关键字而不是位置参数。
>>> defconcat(*args,sep=/):... returnsep.join(args)...>>> concat(earth,mars,venus)'earth/mars/venus'>>>concat(earth,mars,venus,sep=.)'earth.mars.venus'
该用户其它信息

VIP推荐

上海分类信息网-上海免费发布信息-上海新闻网