Final Quiz
Covers the Entire Book — 20 questions.
Final Quiz
Covers the Entire Book — 20 questions.
1 mark
[{"question":"Which of the following correctly creates a list with values 0, 2, 4, 6, 8?","options":["[x for x in range(10) if x % 2 == 0]","[x*2 for x in range(5)]","both a and b","[x for x in range(0, 10, 2)]"],"correct":2},{"question":"What does the enumerate() function return when used in a loop?","options":["Only the index","Only the value","Both index and value as a tuple","A list of all indices"],"correct":2},{"question":"Which keyword do you use to define a function?","options":["function","def","define","func"],"correct":1},{"question":"What is the output of print(type(3.14))?","options":["<class 'int'>","<class 'float'>","<class 'str'>","<class 'decimal'>"],"correct":1},{"question":"Which statement is true about Python sets?","options":["They maintain insertion order","They can contain duplicate elements","They are unordered collections of unique elements","They are immutable"],"correct":2},{"question":"What does the pass keyword do?","options":["Exits the current function","Serves as a placeholder — does nothing","Skips the next iteration","Raises an exception"],"correct":1},{"question":"Which method reads a file and returns its entire content as a string?","options":["read()","readline()","readlines()","get()"],"correct":0},{"question":"What is the purpose of __init__ in a class?","options":["To delete the object","To initialize a new instance's attributes","To define a class method","To create a property"],"correct":1},{"question":"How do you raise a custom exception?","options":["throw Exception()","raise Exception()","emit Exception()","error Exception()"],"correct":1},{"question":"Which of the following is NOT a valid Python data type?","options":["list","array","tuple","dict"],"correct":1},{"question":"What does the //= operator do?","options":["Divides and assigns the float result","Divides and assigns the integer result","Assigns and compares","Performs exponentiation"],"correct":1},{"question":"Which function checks if all characters in a string are digits?","options":["isnum()","isdigit()","isalpha()","isnumber()"],"correct":1},{"question":"What does a .pyc file contain?","options":["Python source code","Compiled Python bytecode","Configuration settings","Documentation strings"],"correct":1},{"question":"Which standard library module provides support for working with JSON?","options":["xml","json","csv","os"],"correct":1},{"question":"What is method overriding?","options":["Defining multiple methods with the same name and different parameters","Replacing a method in a subclass that was inherited from the parent","Hiding a method from external access","Calling a method with too many arguments"],"correct":1},{"question":"Which syntax creates an empty dictionary?","options":["[]","{}","set()","dict[]"],"correct":1},{"question":"What does the continue statement do?","options":["Exits the loop immediately","Skips the rest of the current iteration and moves to the next","Restarts the loop from the beginning","Pauses execution"],"correct":1},{"question":"Which of the following is a valid import statement?","options":["import os","#include <os>","using os","require 'os'"],"correct":0},{"question":"What is the output of list('abc')?","options":["['abc']","['a', 'b', 'c']","['a,b,c']","Error"],"correct":1},{"question":"Which of the following is the best way to swap two variables x and y in Python?","options":["temp = x; x = y; y = temp","x, y = y, x","swap(x, y)","x = y; y = x"],"correct":1}]
covers-the-entire-book