

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This Python Function allow us to change functionality easily, and different programmers can work on different functions. The syntax to define a function is: To ...
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!


2. USER DEFINED FUNCTIONS: A function defined by programmer/user according to their need
the ‘def’ keyword before its name. And its name is to be followed by parentheses, before a colon(:). Parenthesis may contain argument(s) i.e. parameter(s).
#Syntax of function without parameters def functionname( ): "function_docstring" Statement . . #Syntax of function without parameters def functionname( arg1,arg2,.... ): "function_docstring" Function statement . . return (expression)
Example:
def evenOdd( x ): if (x % 2 == 0): print "even" else: print "odd"
evenOdd(2) evenOdd(3)