Previous post: Next Post:
Python #10-Dictionaries in Python Python #12-Recursion functions in python
Syntax:
def functionName(arguments):
statements
Note Worthy: def is the keyword in python which is used to define a function in python.
Example:
Let me create a function to add two number and print the output...
Source code:
def add(a, b):
print a+b
add(1, 2)
Output:
3
Explanation:
#Line 1: def add(a,b) :
This line is used to declare a functions with an arguments a and b.
#Line 2: print a+b
This is the print statement inside the add() which also perform a+b operation.
#Line 3: add(5, 2)
This is said to be the function call..Here add(5, 2) is the calling function which will call the add() and pass the arguments 5 and 2.
Hope some more example will get you clear view in functions, here are some example try it...
Addition, Subtraction, Multiplication and Division example:
Python #10-Dictionaries in Python Python #12-Recursion functions in python
what are functions?
functions are the set of programs instructions that perform a specific task.
Syntax:
def functionName(arguments):
statements
Note Worthy: def is the keyword in python which is used to define a function in python.
Example:
Let me create a function to add two number and print the output...
Source code:
def add(a, b):
print a+b
add(1, 2)
Output:
3
Note: Use the 🖉 for code editor. Use the▶ to view the output.
Explanation:
#Line 1: def add(a,b) :
This line is used to declare a functions with an arguments a and b.
#Line 2: print a+b
This is the print statement inside the add() which also perform a+b operation.
#Line 3: add(5, 2)
This is said to be the function call..Here add(5, 2) is the calling function which will call the add() and pass the arguments 5 and 2.
Hope some more example will get you clear view in functions, here are some example try it...
Addition, Subtraction, Multiplication and Division example:
Note: Use the 🖉 for code editor. Use the▶ to view the output.
Have any doubts don't forget to comment below!
Thanks and Regards,
Tech Bird
Comments