0

call a function with an argument

Hi guys, I'm new to python and I need your help. I want to call a function which prints a range(x, y) defined by an argument. For example this simple function: def func(): for x in range(0, 100): print("hello") func() How to define the range by the argument instead of the func itself? Thank you and sorry for bad English!

13th Sep 2016, 9:54 AM
Anastasia Fallena
Anastasia Fallena - avatar
2 Answers
+ 3
def printHello(start=0,stop=100): for i in range(start,stop): print("Hello") # putting start=0 and stop=100 if you don't pass the two arguments: 0 and 100 will be the 2 values ... >>> printHello() Hello .... (99 times) # if you pass the two arguments (different from 0 and 100) the new arguments will be used by the function >>> printHello(1,6) Hello Hello Hello Hello Hello
13th Sep 2016, 10:01 AM
Giovanni Gatto
Giovanni Gatto - avatar
+ 1
def func(s,f): for x in range(s, f): print("hello") func(1,5)
13th Sep 2016, 9:58 AM
Textobot
Textobot - avatar