+ 1

What is "def" in python? What is it used for? Few examples?

python

20th Dec 2016, 11:03 PM
blazerfumes
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.
20th Dec 2016, 11:09 PM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar
0
def is used for defining functions.
20th Dec 2016, 11:29 PM
Rishi Anand
Rishi Anand - avatar
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.
21st Dec 2016, 1:30 AM
Ateendra Gaur
Ateendra Gaur - avatar