+ 1
will it work without return! by using some variable names in line 2, i tried i couldn't make it worked😀
2 odpowiedzi
+ 3
visph Thank you brother really appreciate💙
+ 2
"""
yes, you could, but to assign a global variable from inside a function, you must declare it with 'global' keyword...
so, your code could either be:
"""
def seven_add():
global number
number+=7
results = []
numbers = [1, 2, 3]
for number in numbers:
seven_add()
results.append(number)
print(results)
# or:
def seven_add(num):
global res
res = num+7
results = []
numbers = [1, 2, 3]
for number in numbers:
seven_add(number)
results.append(res)
print(results)