InterviewSolution
| 1. |
Define functions with example. |
|
Answer» A function is a block of organized, reusable code that is used to perform a single, related action. Functions provides better modularity for your application and a high degree of code reusing.As you already know, Python gives you many built-in functions like print( ) etc. but you can also create your own functions. These functions are called user – defined functions. Syntax: def functionname(parameters): “function_docstring” function_suite return[expression] By default, parameters have a positional behavior, and you need to inform them in the same order that they were defined. Example: Here is the simplest form of a Python function. This function takes a string as input parameter and prints it on standard screen. def printme(str): “This prints a passed string into this function” print str return |
|