16th Aug 2016, 11:18 AM
Blackhat
Blackhat - avatar
3 odpowiedzi
+ 1
Some times you need a function that's not included in python , so you can create your own function with (def) and use it as much as you want by calling it.. Ex. def my_func(): print("My own function") my_func() >>> 'My own function' >>>
16th Aug 2016, 11:54 AM
Abdulrahman Alshab
Abdulrahman Alshab - avatar
+ 1
Def indicates you are defining your own function (also known as a method). What a function is is simply a piece of code you can use over and over and over. If I were to say: Def MyFunc(args): print(args) MyFunc(5) This would print out the number 5. I am sending the argument of 5 as the variable 'args' and printing it out in the function's code.
10th Oct 2016, 6:40 PM
irock2336
0
It is used if you want to run a code multiple times in your program but you don't want to repeat it many times thus saving space and making your code more readable and less complicated. example: def print_i(): print("Hi") print_i() print("Hello") print_i() Result: Hi Hello Hi
17th Aug 2016, 4:50 PM
Moh Kur
Moh Kur - avatar