किसी फ़ंक्शन को परिभाषित करना केवल उसे एक नाम देता है, उन मापदंडों को निर्दिष्ट करता है जिन्हें फ़ंक्शन में शामिल किया जाना है और कोड के ब्लॉक की संरचना करता है।
एक बार किसी फ़ंक्शन की मूल संरचना को अंतिम रूप देने के बाद, आप इसे किसी अन्य फ़ंक्शन से या सीधे पायथन प्रॉम्प्ट से कॉल करके निष्पादित कर सकते हैं। प्रिंटमे () फ़ंक्शन को कॉल करने का उदाहरण निम्नलिखित है -
#!/usr/bin/python
# Function definition is here
def printme( str ):
"This prints a passed string into this function"
print str
return;
# Now you can call printme function
printme("I'm first call to user defined function!")
printme("Again second call to the same function") आउटपुट
जब उपरोक्त कोड निष्पादित किया जाता है, तो यह निम्नलिखित परिणाम उत्पन्न करता है -
I'm first call to user defined function! Again second call to the same function