简体   繁体   中英

looping a function with different arguments in python

I am trying to loop over a function with different numbers as arguments. I want to test the numbers between 1 and 20 for example. What is the way to go?

def calculation(w):
     print_me_w = w+1
     print (print_me_w)

calculation(1)
for i in range(1, 21):
    calculation(i)

You can use the range function for this.

def calculation(w):
    print_me_w = w+1
    print (print_me_w)

for i in range(1,21):
    calculation(i)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM