Answer the question
In order to leave comments, you need to log in
What does sum = arg[0] code snippet do? (explained below)!?
Here's a question: there's an exercise in Lutz's book on learning python. You need to create a function that will calculate an arbitrary number of arguments.
def adder(*args):
print('adder', end=" ")
sum = args[0] # остальное понимаю, а вот тут не понятно, почему именно 0, как этот кусок когда работает? И пробовал менять значения с [0] на [1] и в случае с единицей при последующем присваивании аргументов он их перемножал, а не складывал, как в случае с [0].
for next in args[1:]: # тут тоже не до конца понял
sum =+ next
return sum
Answer the question
In order to leave comments, you need to log in
Here is the place in the official docs:
https://docs.python.org/3/tutorial/controlflow.htm...
Here is a good article on this topic:
https://tproger.ru/translations/python-args-and- kwargs/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question