Python

Python Quiz with answers – Part 3

Practical questions to test your knowledge of Python programming – Part 3

Which of the following uses the id() function in python?
id() returns the object identifier
An object does not have a unique identifier
All the answers are true
None of these answers is true.

Correct!

Wrong!

What will be the output of the following code?
def somme(init = 5, *nbr, **key):
c = init
for n in nbr: c+=n
for k in key:
c+=key[k]
return c
print(somme(100,2,2, x=20, y=10))
136
134
100
122

Correct!

Wrong!

What will be the output of the following code?
import re
sentence = 'I am fine'
regex = re.compile('(?P<animal>w+) (
P<verb>w+) (?P<adjective>w+)'
)
matched = re.search(regex, sentence)
print(matched.groupdict())
{‘subject’: ‘I’, ‘verb’: ‘am’, ‘adjective’: ‘fine’}
(‘I’, ‘am’, ‘fine’)
‘I am fine’
‘am’

Correct!

Wrong!

What will be the output of the following code?
try: 
list = 2*[0]+2*[5]
x = list[2]
print('OK!')
except IndexError:
print('Block Except!')
else:
print('Block Else!')
finally:
print('Block Finally!')
OK!
Block Else!
Block Finally!
All the answers are true

Correct!

Wrong!

Suppose that list1 is [2, 3, 4, 5, 1, 20, 6], what will be the value of list1 after list1.pop(1)?
[2, 3, 4, 5, 20, 6]
[2, 1, 4, 5, 1, 20, 6]
[2, 3, 4, 5, 1, 20, 6, 1]
[2, 4, 5, 1, 20, 6]

Correct!

Wrong!

Suppose we have two sets (s1 and s2) so what is the output of S1 + S2
Add the elements of the two sets.
Remove repeating items and add both sets.
Cannot perform this type of operation.
The output will be saved in S1.

Correct!

Wrong!

Are String objects mutable?
Yes
No

Correct!

Wrong!

Python is a compiled language
True
False

Correct!

Wrong!

Can the use of parentheses change the order of evaluation?
Yes
No

Correct!

Wrong!

What is the correct syntax for reading from a text file stored in "c:file.txt"?
f = open('c:file.txt', 'r')
f = open(file='c:file.txt', 'r')
f = open.file('c:file.txt', 'r')
f = open('c:file.txt', 'r')

Correct!

Wrong!

Share the quiz to show your results !

Subscribe to see your results

Python Quiz – Part 3

I got %%score%% of %%total%% right

%%description%%

%%description%%

Loading...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button