Answer the question
In order to leave comments, you need to log in
How can I pass nothing to the function so that the default value would work?
I'm just learning python so I don't know if it's possible to pass an empty to a function so that the default value would work. After all, I have two functions where one passes a value to the other, and in order not to write the default value twice, is it possible to write an empty one.
Is there such a value in python?
Using if else is not suitable because if there are several variables, then you have to write all combinations.
def test_1(arr_1=[1,232,1134,134,1113,442,23,1134,313,4,5232,533,32], arr_2=[393,399,23009,11999,309,399,9]):
#Просто выводит либо значения по умолчанию либо то что в него передали неважно что
print("{}-{}".format(arr_1,arr_2))
def test_2(val_1=None,val_2=None):
#сокращенно
test_1(val_1,val_2)
#C использованием if else
if val_1== None and val_2==None:
test_1()
elif val_1== None and not val_2==None:
test_1(arr_2=val_2)
elif val_2== None and not val_1==None:
test_1(val_1)
# Дальше исполняет что то
test_1()
test_2()
test_2('f')
test_2('f','D')
test_2(val_2='D')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question