What is the output of this code? def func(val1, val2=2, val3=7, val4=1): return val1**val2**val3
print(func(val2=2, val1=2, val3=4))
Correct
Incorrect
Question 2 of 14
2. Question
How will you not create a dictionary?
Correct
Incorrect
Question 3 of 14
3. Question
In the following code, how will you get to the value 7?
list = [
‘milk’,
‘cheese’,
{
‘block’: 1,
‘utensils’:
{
‘cups’ : 5,
‘spoons’ : 7
},
‘color’: ‘yellow’
},
‘butter’,
‘ghee’
]
Correct
Incorrect
Question 4 of 14
4. Question
Which of these can you use as a dictionary key? Please select 3 correct answers
Correct
Incorrect
Question 5 of 14
5. Question
What does the following code print? a = [1, 2, 3] a is a[:]
Correct
Incorrect
Question 6 of 14
6. Question
In the following code, what is the output? a = 2 b = 3 a and b
Correct
Incorrect
Question 7 of 14
7. Question
Which of the following return True for a string? Please select 3 correct answers
Correct
Incorrect
Question 8 of 14
8. Question
What is the value of round(12.5) – round(11.5)?
Correct
Incorrect
Question 9 of 14
9. Question
Select the correct statements: I. We define classes and functions with the def keyword II. A class can define an object III. A class can define a function IV. A function can define a class
Correct
Incorrect
Question 10 of 14
10. Question
Select the correct output for this code: try: raise Exception print(2/0) except Exception as e: print(e)
Correct
Incorrect
Question 11 of 14
11. Question
What is the output of this code? l1 = [1, 2, 3] l2 = l1 l3 = l1.copy() l4 = list(l1) l1[0] = [7] print(l1, l2, l3, l4)
Correct
Incorrect
Question 12 of 14
12. Question
What is the output of this code? l1 = [1, [2, 3], 4] l2 = l1.copy() l2[1][1]=7 print(l1, l2)
Correct
Incorrect
Question 13 of 14
13. Question
What is the size of an empty tuple in Python?
Correct
Incorrect
Question 14 of 14
14. Question
What is the output of this code? def show(list, length): print(list[length-1], end=’’) show(list, length-1)
show([1,2,3,4,5],5)
Correct
Incorrect
Here we come to the end of the Python Quiz. Hope you enjoyed it!!!
If you have any queries and suggestions regarding the Python online quiz, share it in the comment section.
Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google
DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.
for 12th question the answer is option a it’s not b,if we use l2=l1 then option b is correct but here you used l2=l1.copy() while using this statement it cannot affect the l1 list
“The correct option is option b becasue we have created copy of the list l1. But we are modifying the element of the list element inside the list. But if we modify the list element as a whole, your anser would have been correct. For example, if the code would have been l1 = [1, [2, 3], 4] l2 = l1.copy() l2[1]=7 print(l1, l2) Then the output would have been [1, [2, 3], 4] [1, 7, 4]. Hope I could answer your question.”
Hello, I am new to programming and I wish to enrol in the course so that I can have access to your facilitators but I am financially incapable. Please, If I can go through all the tutorials in the blogs and creating a portfolio with the projects on the website, will they be enough for me to develop something on my own or secure a job.
This output you gave for this code is correct. But this code is different from the one given in question 14. The third line should be show(list, length-1). Hope I could solve your query.
If i am not wrong the Q.8 answer would be 1 instead 0.
Hello Apeksha,
The answer is zero as Python uses round to even strategy for .5 values. Try running the script in Python and you will understand.
for 12th question the answer is option a it’s not b,if we use l2=l1 then option b is correct but here you used l2=l1.copy() while using this statement it cannot affect the l1 list
l2=l1.copy() creates a shallow copy. The reference to the list [2, 3] is copied, not the list itself.
Therefore l1 is affected.
“The correct option is option b becasue we have created copy of the list l1. But we are modifying the element of the list element inside the list. But if we modify the list element as a whole, your anser would have been correct. For example, if the code would have been l1 = [1, [2, 3], 4]
l2 = l1.copy()
l2[1]=7
print(l1, l2) Then the output would have been [1, [2, 3], 4] [1, 7, 4]. Hope I could answer your question.”
Hello, I am new to programming and I wish to enrol in the course so that I can have access to your facilitators but I am financially incapable. Please, If I can go through all the tutorials in the blogs and creating a portfolio with the projects on the website, will they be enough for me to develop something on my own or secure a job.
Thank
Hi,
Please send an email regarding your queries at this id [email protected]. Our team will help you in the best possible way.
def show(list,length):
print(list[length-1],end= ”)
print(list,length-1)
show([1,2,3,4,5],5)
I am getting 5[1, 2, 3, 4, 5] 4, do I missed something here.
In the function, the 3rd line should be ‘show(list, length-1)’ instead of ‘print(list,length-1)’
This output you gave for this code is correct. But this code is different from the one given in question 14. The third line should be show(list, length-1). Hope I could solve your query.
Very nice, this set of questions is little tough as compared previous two sets.
Yes
Excellent
Python Quiz
part 1= 100%
Part 2 = 85.71%
Part3 = 100%
Hello. I have a questio about Q13 size of a tuple.
Why Python tells me that the empty tuple has 40bytes?
import sys
tuple=()
print(“Size of tuple: ” + str(sys.getsizeof(tuple)) + “bytes”)
Size of tuple: 40bytes
Q13
when i use my pc ().__sizeof__() the result is 24
when i use my android (pydroid 3) the result is 12
python quiz 3
Q7
option 2
“s[:] is s” should return False