Python Loops , Keywords and Functions Quiz
Question 1
Can an inner function access variables from the enclosing function?
No, Python does not support this
Only if declared global
Yes, via lexical scoping
Only if passed explicitly as arguments
Question 2
To include the use of functions which are present in the random library, we must use the option:import random
import random
random.h
import.random
random.random
Question 3
What will be the output of the following code?
def outer():
x = 10
def inner():
nonlocal x
x += 5
return x
return inner
closure = outer()
print(closure())
print(closure())
15
20
15
15
10
15
5
5
Question 4
What is the output of the following segment :
print(chr(ord('A')))
A
B
a
Error
Question 5
What is the output of the following program :
y = 8
z = lambda x : x * y
print(z(6))
48
14
64
None of the above
Question 6
What is called when a function is defined inside a class?
Module
Class
Another Function
Method
Question 7
Which of the following is the use of id() function in python?
Id returns the identity of the object
Every object doesn’t have a unique id
All of the mentioned
None of the mentioned
Question 8
What is the output of the following program :
import re
s = 'horses are fast'
regex = re.compile(r'(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)')
matched = re.search(regex, s)
if matched:
print(matched.groupdict())
{‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
(‘horses’, ‘are’, ‘fast’)
‘horses are fast’
‘are’
Question 9
Suppose li is [3, 4, 5, 20, 5, 25, 1, 3], what is li after li.pop(1)?
[3, 4, 5, 20, 5, 25, 1, 3]
[1, 3, 3, 4, 5, 5, 20, 25]
[3, 5, 20, 5, 25, 1, 3]
[1, 3, 4, 5, 20, 5, 25]
Question 10
There are 14 questions to complete.