Available Questions About Python Quizzes
1. What does the strip() method do when applied to a string?
Removes all whitespace characters
Removes leading and trailing whitespace
Replaces whitespace with a hyphen
Splits the string into a list
2. Which of the following is not a valid way to import a module in Python?
import math
from math import sqrt
import sqrt from math
import math as m
3. print(bool(0), bool(3), bool(-1))
False False False
False True True
True False False
True True True
4. Which of the following is the correct way to read all the contents of a file into a single string?
f.readall()
f.readlines()
f.read()
f.readfile()
5. What is the purpose of the isinstance() function in Python?
To check if an object is an instance of a class
To create a new instance of a class
To check if two objects are the same instance
To get the class of an object
6. How do you create a set in Python?
s = {}
s = set()
s = []
s = ()
7. Which of the following methods is used to find the index of an element in a list?
index()
find()
locate()
search()
8. Which of the following statements correctly creates a tuple?
t = (1, 2, 3)
t = [1, 2, 3]
t = {1, 2, 3}
t = 1, 2, 3
9. 3 * (1 + 2) ** 2 - 4
17
23
25
29
10. Which of the following methods will combine the contents of two dictionaries in Python 3.9 and later?
dict.update()
dict.extend()
dict.merge()
| (pipe operator)
11. Which of the following is not a valid Python variable name?
my_var
_myvar
2myvar
myVar
12. How can you access the first element of a list my_list?
my_list(0)
my_list[0]
my_list.first()
my_list.get(0)
13. print(type([]))
<class 'dict'>
<class 'list'>
<class 'tuple'>
<class 'set'>
14. Which of the following loops is used to iterate over a sequence?
for
while
do-while
If
15. 5 // 2
2.5
2
3
1