3 Réponses
+ 1
A function is a block of organized, reusable code that is used to perform a single, related action. Functionsprovide better modularity for your application and a high degree of code reusing. As you already know, Pythongives you many built-in functions like print(), etc. but you can also create your own functions.
0
def is used for defining functions.
0
def is used for definig functions in python.
Specifically def is nothing but a recursion in Python.
Example:
def fact(n):
if(n==1):
return 1
else :
return n*fact(n-1)
x=int(input())
print(fact(x))
here
fact() is a function defined by using def.
It will print the factorial of the number input by user.