+ 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?
2 Réponses
+ 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
+ 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.