Is it possible to set a default value for a list of variable arguments in Python 3?
Sort of:
def do_it(*args=(2, 5, 21)): pass
Interestingly, the list of variable arguments is of type tuple, but there is no tuple here.
tuple
If not syntactically, then depending on what behavior you want:
def do_it(*args): if not args: args = (2, 5, 21)
or
def do_it(a=2, b=5, c=21, *args): args = (a,b,c)+args
must do it.
Initializing such a list is usually not a good idea.
. , , , . ,
def f(a, L=[]): L.append(a) return L print f(1) print f(2) rint f(3)
[1] [1, 2] [1, 2, 3]
, - , , .
Source: https://habr.com/ru/post/1743845/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1743840/how-can-i-convert-connection-data-lines-to-block-of-schemes-using-perl&usg=ALkJrhg9MmsKkrF-_btIA9fQy1yNpxVuDQLearning PHP: Good examples of building-based lessons? - phpCryptic C ++ "thing" (function pointer) - c ++serializing objects in C ++ and saving as blob type in mysql - c ++Does GTK + use native widgets on Windows and OS X, or are they emulated? - windowsCannot get Javac to work on Mac OS X - javaInternet Explorer 8 - Div disappears when resized - htmlSimple Pascal Types - pascalradio button loses value in postback - c #Eclipse CORBA Plugin - eclipseAll Articles