11. You can also create your own functions, these functions are called?
A. built-in functions
B. user-defined functions
C. py function
D. None of the above
Answer
#Ans : B Explanation: 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.
12. Function blocks begin with the keyword?
A. define
B. fun
C. function
D. def
Answer
#Ans : D Explanation: Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ).
13. The code block within every function starts with a ?
A. ;
B. ::
C. :
D. %
Answer
#Ans : C Explanation: The code block within every function starts with a colon (:) and is indented.
14. A return statement with _____ arguments.
A. No
B. 1
C. 2
D. Any
Answer
#Ans : A Explanation: The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None.
15. ___________ are the arguments passed to a function in correct positional order.
A. Required arguments
B. Keyword arguments
C. Default arguments
D. Variable-length arguments
Answer
#Ans : A Explanation: Required arguments are the arguments passed to a function in correct positional order. Here, the number of arguments in the function call should match exactly with the function definition.
16. Which of the following will print the pi value defined in math module?
A. print(pi)
B. print(math.pi)
C. from math import pi
print(pi)
D. from math import pi
print(math.pi)
Answer
#Ans : C Explanation: from math import pi, print(pi) will print the pi value defined in math module. So, option C is correct.
17. Which operator is used in Python to import modules from packages?
A. .
B. *
C. ->
D. &
Answer
#Ans : A Explanation: . operator is used in Python to import modules from packages. So, option A is correct.
18. Where is funcstion defined?
A. Module
B. class
C. Another Function
D. All of the above
Answer
#Ans : D Explanation: Function can be defined in module, class and another function. So, option D is correct.
19. Lambda is a function in python?
A. True
B. False
C. Lambda is a function in python but user can not use it.
D. None of the above
Answer
#Ans : A Explanation: lambda is an anonymous function in Python. So, option A is correct.
20. What is a variable defined outside a function referred to as?
A. local variable
B. global variable
C. static Variable
D. automatic variable
Answer
#Ans : B Explanation: Variable defined outside a function is referred as Global variable and can be accessible by other functions. So, option B is correct.
21. What is the output of the following program?
z = lambda x : x * x
print(z(6))
A. 6
B. 36
C. 0
D. error
Answer
#Ans : B Explanation: This lambda function will calculate the square of a number. So, option B is correct.
22. What is the output of the following program?
print(chr(ord(chr(97))))
A. a
B. A
C. 97
D. error
Answer
#Ans : A Explanation: Outer chr and ord will cancel out and we will be left with chr(97) which will return "a". So, option A is correct.
23. Choose the correct option with reference to below Python code?
def fn(a):
print(a)
x=90
fn(x)
A. x is the formal argument.
B. a is the actual argument.
C. fn(x) is the function signature.
D. x is the actual argument.
Answer
#Ans : D Explanation: x is the actual argument that is the correct option with reference to below Python code. So option D is correct.
24. Which one of the following is incorrect?
A. The variables used inside function are called local variables.
B. The local variables of a particular function can be used inside other functions, but these cannot be used in global space
C. The variables used outside function are called global variables
D. In order to change the value of global variable inside function, keyword global is used.
Answer
#Ans : B Explanation: The local variables of a particular function can be used inside other functions, but these cannot be used in global space is one of the following is incorrect. So the option B is correct.