+ 2
Please I need enlightenment on defining functions in Python
Still a bit hard to comprehend
2 Réponses
+ 5
Defining a function just means that you create your own function to use it whenever required. Let's take an example:-
I want to print "Hello world" 5 times and then I want to print "sololearn" 3 times and then I want to print "defining function" 8 times and I want to print it again and again after adding some more code after that
You will do it like this without def:-
print("Hello world" *5)
print ("sololearn*3)
print ("defining function" *8)
So, you have to write it again and again for doing so.
With def function:-
def wordprint():
print("Hello world" *5)
print ("sololearn*3)
print ("defining function" *8)
Whenever you'll call wordprint it will print above words given number of times. It's very useful in cases where we have to write code again and again.
Hope it's clear now🙂
+ 4
Please use 'Python' in the thread tags to improve context clarity 👍