+ 1

What is def() and return function?

I am just starting out on python..although still in while loop function..I mostly see def() and return functions a lot..so was Keen on what those functions mean..would appreciate an answer..

28th Mar 2017, 11:23 PM
Prabin gurung
Prabin gurung - avatar
1 Odpowiedź
+ 2
def is when you define a function def add(): x=3 return x this is an example of a very basic function. it is declared with "def". given a name "add" and has no arguments "()".. inside this function is does stuff. in this case, it declares x to be 3. finally it returns x. so by calling add() it gives you 3. more useful example- def add(a,b): c=a+b return c This one defines a function called "add" with 2 arguments "a,b". when you call it with add(2,3) it will take a and b, add them together and return them. so add(2,4) returns 6. add(3,1) returns 4
29th Mar 2017, 1:56 AM
LordHill
LordHill - avatar