Q: Which are the advantages of functions in python?
Solution: None.
Q: What are the two main types of functions?
Solution: Built-in functions and user defined ones. The built-in functions are part of the Python language. Examples are: dir(), len() or abs(). The user defined functions are functions created with the def keyword.
Q: Where is function defined?
Solution: Functions can be defined inside a module, a class or another function.
Q: What is called when a function is defined inside a class?
Solution: None.
Q: Which of the following is the use of id() function in python?
Solution: Each object in Python has a unique id. The id() function returns the object’s id.
Q: Which of the following refers to mathematical function?
Solution: Functions that are always available for usage, functions that are contained within external modules, which must be imported and functions defined by a programmer with the def keyword. Eg: math import sqrt A sqrt() function is imported from the math module.
Q: What will be the output of the following Python code? def cube(x): return x * x * x x = cube(3) print x
Solution: A function is created to do a specific task. Often there is a result from such a task. The return keyword is used to return values from a function. A function may or may not return a value. If a function does not have a return keyword, it will send a none value.
Q: What will be the output of the following Python code? def C2F(c): return c * 9/5 + 32 print C2F(100) print C2F(0)
Solution: The code shown above is used to convert a temperature in degree celsius to fahrenheit.
Q: What will be the output of the following Python code? def power(x, y=2): r = 1 for i in range(y): r = r * x return r print power(3) print power(3, 3)
Solution: The arguments in Python functions may have implicit values. An implicit value is used, if no value is provided. Here we created a power function. The function has one argument with an implicit value. We can call the function with one or two arguments.
You Have Score    | /9 |