This Quiz contains totally 25 Questions each carry 1 point for you.
Which of the following is NOT a built-in data type in Python?
list
set
array
dictionary
Correct!
Wrong!
Which of the following is a valid variable name in Python?
2data
data_2
data-2
None of the above
Correct!
Wrong!
What will be the output of the following code snippet?
if not (3 > 4):
print("Penguin")
else:
print("Polar Bear")
if not (3 > 4):
print("Penguin")
else:
print("Polar Bear")
Penguin
Polar Bear
SyntaxError
None
Correct!
Wrong!
Which loop is particularly useful when you don't know ahead of time how many times you need to iterate?
for loop
while loop
do-while loop
repeat-until loop
Correct!
Wrong!
Which keyword allows a function to return multiple values in Python?
return
yield
break
continue
Correct!
Wrong!
How do you create a new class in Python?
class MyClass {}
class MyClass():
def MyClass:
create MyClass():
Correct!
Wrong!
Which statement is true about inheritance in Python?
Python supports multiple inheritance.
Python does not allow classes to inherit from more than one class.
Inheritance is not supported in Python.
Python classes can only inherit from classes in the same module
Correct!
Wrong!
What are decorators in Python?
A way to change variable values
Functions that modify the functionality of other functions or methods
A tool to loop through data structures
A data type for storing collections of data
Correct!
Wrong!
Which of the following is true about Python generators?
Generators are a type of class in Python.
Generators allow for the generation of arrays.
Generators produce items only once and only when required, saving memory.
Generators execute all their code at once.
Correct!
Wrong!
What is the purpose of an API in a software application?
To increase the processing speed of the application
To serve as the interface between different software programs, enabling them to communicate
To reduce the storage space the application uses
To enhance the graphical interface of the application
Correct!
Wrong!
Which module in Python is commonly used to interact with SQL databases?
PySQL
MySQLdb
database.py
SQLconnector
Correct!
Wrong!
What is the primary purpose of the NumPy library in Python?
Web scraping
Machine learning models
Working with arrays and matrices in a highly efficient way
Creating graphical user interfaces
Correct!
Wrong!
Why is Pandas preferred for data analysis in Python?
It simplifies data manipulation and analysis.
It is the only library available for Python that can handle data.
It enhances the speed of mathematical calculations on arrays.
It is used for developing mobile applications.
Correct!
Wrong!
What does the following code output?
s = {1, 2, 3, 2}
print(len(s))
s = {1, 2, 3, 2}
print(len(s))
3
4
SyntaxError
TypeError
Correct!
Wrong!
Which of the following is true about tuples in Python?
Tuples are mutable.
Tuples can contain elements of different data types.
Tuples are faster to iterate through than lists because they are mutable.
You can add elements to a tuple using the append() method.
Correct!
Wrong!
What will be the output of the following code snippet?
d = {'a': 1, 'b': 2, 'c': 3}
print(d['b'])
d = {'a': 1, 'b': 2, 'c': 3}
print(d['b'])
1
2
'b'
KeyError
Correct!
Wrong!
Which method is used to convert the first character of each word in a string to uppercase?
capitalize()
title()
upper()
swapcase()
Correct!
Wrong!
How can you check if a string, s, ends with the substring "py"?
s.ends_with("py")
s.endswith("py")
s.contains("py", -2)
s.find("py") == len(s) - 2
Correct!
Wrong!
What does the following code snippet illustrate about tuples?
t = (1, [2, 3], 4)
t[1].append(4)
print(t)
t = (1, [2, 3], 4)
t[1].append(4)
print(t)
Tuples are completely immutable.
Elements within a tuple can be mutable.
Tuples can only contain immutable elements.
This code results in a TypeError.
Correct!
Wrong!
What will be the result of the following set operation?
set1 = {1, 2, 3}
set2 = {3, 4, 5}
result = set1.intersection(set2)
print(result)
set1 = {1, 2, 3}
set2 = {3, 4, 5}
result = set1.intersection(set2)
print(result)
{1, 2, 3, 4, 5}
{3}
{} (an empty set)
{1, 2, 4, 5}
Correct!
Wrong!
What does the following Python code snippet output?
my_string = "Hello, World!"
print(my_string[-1])
my_string = "Hello, World!"
print(my_string[-1])
H
!
d
o
Correct!
Wrong!
What does the following Python code snippet output?
my_list = ['a', 'b', 'c', 'd', 'e']
print(my_list[1:4])
my_list = ['a', 'b', 'c', 'd', 'e']
print(my_list[1:4])
['a', 'b', 'c']
['b', 'c', 'd']
['b', 'c', 'd', 'e']
['c', 'd', 'e']
Correct!
Wrong!
How do you extract 'Python' from the string s = 'HelloPythonWorld' using slicing?
s[5:11]
s[5:12]
s[6:11]
s[6:12]
Correct!
Wrong!
Given a multidimensional list matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], how do you access the element '8'?
matrix[2][1]
matrix[1][2]
matrix[3][2]
matrix[2][3]
Correct!
Wrong!
Share the quiz to show your results !
Subscribe to see your results
Ignore & go to results
Python-Quiz
You got %%score%% of %%total%% right
%%description%%
%%description%%
Loading...
