+ 1

Understanding a def operation.

def print_nums(x): for i in range(x): print(i) return print_nums(10) Can anyone please explain what did line one do? what is the "(X)" in the end of line 1 do?

3rd Dec 2018, 10:32 AM
ephraim
ephraim - avatar
2 Respuestas
+ 3
Line 1 (to the return statement) is function defination and x is the parameter that is passed https://www.programiz.com/JUMP_LINK__&&__python__&&__JUMP_LINK-programming/function
3rd Dec 2018, 11:32 AM
Rstar
Rstar - avatar
+ 3
In first line you are creating a new function.function name is print_nums and (x) is we are passing parameter in function.we need some parameters in function according to our need to work with function. e.g Let you have a x variable and you want to print it with the help of function.you can create a function and pass a parameter with name anything let(x) which refer to x variable means now function has x variable copy,which you want to print.here x is parameter for our function. Other code is function logic.
3rd Dec 2018, 4:39 PM
Maninder $ingh
Maninder $ingh - avatar