Python Quiz by azka.xdlabin QuizApril 6, 2025 Python Quiz 1 / 106 What is the correct file extension for Python files? .pt .pyt .py .pyth 2 / 106 Which of the following is a valid variable name in Python? 1name name_1 name-1 @name 3 / 106 What is the output of the following code?print(3 * "hi") hi hi hi hihihi error 3hi 4 / 106 Which keyword is used to define a function in Python? define def function func 5 / 106 What will be the output of this code?x = 5y = "5"print(x + int(y)) 55 10 Error 5 6 / 106 Which data type is mutable in Python? tuple string list int 7 / 106 What does this code do?for i in range(3): print(i) Prints 1 2 3 Prints 0 1 2 Prints 0 1 2 3 Error 8 / 106 Which operator is used for exponentiation in Python? ^ ** ^^ ^* 9 / 106 What is the output of type("Hello")? string str 10 / 106 Which of the following is NOT a Python data type? set float real dict 11 / 106 Which of the following is a correct way to assign a value to a variable in Python? x == 5 5 = x x = 5 x := 5 12 / 106 What is the result of this code?x = 3x += 2print(x) 2 3 5 x + 2 13 / 106 Which of the following variables is written using snake_case? userAge UserAge user_age userage 14 / 106 Which of the following variables is written using snake_case? userAge UserAge user_age userage 15 / 106 What will this code output?a = 5b = aa = 10print(b) 10 5 a Error 16 / 106 Which keyword is used to declare a variable in Python? var let declare None of the above 17 / 106 What data type is the variable x after this code?x = "10" int str float bool 18 / 106 What is the value of x after this code runs?x = 7x = x + 3 3 10 7 0 19 / 106 Which of the following is NOT a valid variable name? my_var 2ndName name2 _value 20 / 106 What will be the output of the following code?x = 10y = 5print(x + y) x + y 105 15 Error 21 / 106 Which of the following is a correct way to assign a value to a variable in Python? x == 5 5 = x x = 5 x := 5 22 / 106 What is the result of this code?x = "123"print(type(x)) 23 / 106 Which of the following is an immutable data type? list set tuple dict 24 / 106 What will this code return?x = {"a", "b", "c"}print(type(x)) 25 / 106 Which of these is a valid dictionary in Python? [1: "one", 2: "two"] {"one": 1, "two": 2} (1 => "one") "one" = 1, "two" = 2 26 / 106 What is the output of this code?x = (1, 2, 3)print(type(x)) 27 / 106 What is the type of the variable x?x = [1, 2, 3] tuple list set dict 28 / 106 Which data type is used to store multiple values in a single variable? int list str float 29 / 106 What is the data type of the value True? int str bool float 30 / 106 Which of these is an example of a string in Python? 10 '10' 10.5 True 31 / 106 What happens when you try to print an undefined variable?print(score) It prints None It prints 0 It prints score It causes an error 32 / 106 Which of these will create an empty list? list = () list = {} list = [] list = None 33 / 106 What does this code do?nums = [1, 2, 3]nums.insert(1, 99)print(nums) Inserts 99 at index 0 Replaces 2 with 99 Appends 99 to the end Inserts 99 at index 1 34 / 106 How can you access the last item in a list? list[-1] list[0] list[1] list[len] 35 / 106 What is the output of this code?colors = ["red", "blue", "green"]print(len(colors)) 2 3 4 Error 36 / 106 Which method removes the last item from a list? delete() pop() remove() discard() 37 / 106 What will be the result of this code?numbers = [10, 20, 30, 40]numbers[2] = 99print(numbers) [10, 20, 30, 40] [10, 20, 99, 40] [10, 99, 30, 40] Error 38 / 106 How do you add an item to the end of a list? list.add("item") list.insert("item") list.append("item") list.put("item") 39 / 106 What is the index of the first element in a Python list? 1 0 -1 None 40 / 106 What is the output of this code?fruits = ["apple", "banana", "cherry"]print(fruits[1]) apple banana cherry 1 41 / 106 Which of the following creates a list in Python? list = 1, 2, 3 list = {1, 2, 3} list = (1, 2, 3) list = [1, 2, 3] 42 / 106 Which of the following is NOT true about tuples? Tuples are immutable Tuples can store multiple data types Tuples are ordered Tuples have methods to add and remove items 43 / 106 What does the index() method do in a tuple? Adds an element Removes an element Finds the position of an element Slices the tuple 44 / 106 What is the result of this code?t = (1, 2, 3, 4)print(t[-1]) 1 4 3 Error 45 / 106 Which method is used to count how many times an item appears in a tuple? count() index() find() sum() 46 / 106 How can you create a tuple with a single value 5? t = (5) t = 5, t = (5,) t = [5] 47 / 106 Which function returns the number of items in a tuple? length() count() size() len() 48 / 106 What happens when you try to change a value in a tuple?t = (1, 2, 3)t[0] = 9 Tuple is updated Nothing happens It adds a new item Error occurs 49 / 106 What is the output of this code?t = (10, 20, 30)print(t[1]) 10 20 30 1 50 / 106 What is the main difference between a list and a tuple? Tuples are slower Tuples are unordered Tuples can only contain numbers Tuples are immutable 51 / 106 How do you create a tuple in Python? t = [1, 2, 3] t = {1, 2, 3} t = (1, 2, 3) t = 52 / 106 What is the result of this code?a = {1, 2}b = {2, 3}print(a & b) {1, 2, 3} {2} {1} Error 53 / 106 Which method removes and returns a random element from a set? remove() discard() pop() random() 54 / 106 What does clear() do in a set? Removes duplicates Sorts the set Deletes all elements Converts to a list 55 / 106 Which operation finds common elements between two sets? a.union(b) a.difference(b) a.intersection(b) a.symmetric_difference(b) 56 / 106 What will be the result of this code?a = {1, 2, 3}b = {3, 4, 5}print(a.union(b)) {1, 2, 3, 4, 5} {3} {1, 2} Error 57 / 106 What does the discard() method do? Removes an item and returns it Deletes the last item Removes an item if it exists, no error if it doesn’t Removes all items 58 / 106 How do you add an element to a set? s.add() s.append() s.add(4) s.insert(4) 59 / 106 What is the output of this code?s = {1, 2, 2, 3}print(s) {1, 2, 2, 3} {1, 2, 3} [1, 2, 3] Error 60 / 106 What is the main feature of a set in Python? It stores items in order It allows duplicate values It stores unique, unordered items It is mutable and ordered 61 / 106 Which of the following creates a set in Python? s = [1, 2, 3] s = (1, 2, 3) s = {1, 2, 3} s = 62 / 106 Which of the following defines a dictionary in Python? d = [1: "one", 2: "two"] d = (1, "one", 2, "two") d = {1: "one", 2: "two"} d = {1: "one", 2: "two"} 63 / 106 What is a dictionary in Python? An ordered list of elements A collection of key-value pairs A list of numbers A set of characters 64 / 106 Which method is used to get the value of a key without an error if the key doesn’t exist? get() find() search() lookup() 65 / 106 How do you add a new key-value pair to a dictionary? d.append("city", "Paris") d.add("city", "Paris") d["city"] = "Paris" d.insert("city", "Paris") 66 / 106 What will this code print?d = {"a": 1, "b": 2}d["a"] = 3print(d) {"a": 1, "b": 2} {"a": 3, "b": 2} {"a": 3} Error 67 / 106 What does the keys() method return? Only the first key All the values All the keys Key-value pairs 68 / 106 What is the output of this code?d = {"x": 100, "y": 200}print(len(d)) 100 2 1 Error 69 / 106 Which operator is used for "or" condition in Python? || or else | 70 / 106 What will be printed?x = 5if x != 5:print("Not five")else:print("It is five") Not five It is five True True 71 / 106 What is the result of this code?x = 10if x > 5 and x < 15:print("In range") In range Out of range Error Nothing 72 / 106 What does this code print?x = 7if x % 2 == 0: print("Even")else: print("Odd") Even Odd Error 7 73 / 106 What is the output of this code?x = 3if x > 5:print("High")elif x == 3:print("Medium")else:print("Low") High Medium Low Nothing 74 / 106 What keyword is used to check multiple conditions after an if? elseif else if elif then 75 / 106 What is the output of this codex = 10if x > 5:print("Big")else:print("Small") Small Big Nothing Error 76 / 106 Which of the following is a correct if statement in Python? if x = 5: if x == 5: if x === 5: if (x equal 5): 77 / 106 What is the result of this code?d = {"name": "Bob", "age": 30}print("age" in d) False True "30" Error 78 / 106 Which method removes all items from a dictionary? remove() pop() clear() delete() 79 / 106 Which keyword is used to start a for loop in Python? loop for foreach iterate 80 / 106 What is the output of this code?for i in range(3): print(i) 1 2 3 0 1 2 0 1 2 3 1 2 81 / 106 Which keyword starts a while loop in Python? repeat during while loop 82 / 106 What does range(5) generate? [1, 2, 3, 4, 5] [0, 1, 2, 3, 4, 5] [0, 1, 2, 3, 4] 0 to 5 including 5 83 / 106 What is the output of this code?for i in range(5): if i == 3: continue print(i) 0 1 2 3 4 0 1 2 4 0 1 2 1 2 4 84 / 106 What is the output of this code?for i in range(5): if i == 3: break print(i) 0 1 2 0 1 2 3 4 3 4 0 1 2 3 85 / 106 What is the use of break in a loop? It pauses the loop It repeats the loop It exits the loop It skips to the next line 86 / 106 How many times will this loop run?x = 0while x < 3:print(x)x += 1 2 3 4 Infinite 87 / 106 Which of the following defines a function that takes two parameters? def add x y: function add(x, y): def add(x, y): define add(x, y) 88 / 106 What is the output of this code?def greet(): print("Hello!")greet() Hello! greet Nothing Error 89 / 106 Which keyword is used to define a function in Python? function fun define def 90 / 106 What does this code print?count = 0while count < 2: print("Hi") count += 1 Hi Hi Hi Hi Hi Hi Infinite loop 91 / 106 Which loop is better when the number of repetitions is unknown? for loop while loop while loop do loop 92 / 106 What is a function with no return value called? Null function Print function Void function Empty function 93 / 106 What is the output of this code?def add(a, b=5): return a + bprint(add(3)) 3 8 5 Error 94 / 106 Which function call is correct for this definition?def say_hello(name): print("Hello", name) say_hello() say_hello("Alice") say_hello("Alice", "Bob") print say_hello 95 / 106 What will this code output?def square(x): return x * xprint(square(4)) 4 8 16 Error 96 / 106 What does a return statement do in a function? Stops the program Outputs a message Exits the loop Sends a value back from the function 97 / 106 What does this code print?from array import arrayarr = array("i", [10, 20, 30])print(arr[1]) 10 20 30 1 98 / 106 What is the correct way to create an array of integers in Python using the array module? arr = array("i", [1, 2, 3]) arr = [1, 2, 3] arr = int([1, 2, 3]) arr = array([1, 2, 3], "i") 99 / 106 Which Python module provides support for arrays? list array math random 100 / 106 Can a function return multiple values? No Yes, using a list Yes, using a tuple Only one value allowed 101 / 106 What is the scope of a variable declared inside a function? Global Module Local Static 102 / 106 Which method returns the index of a value in the array? find() locate() index() position() 103 / 106 How do you remove an element from an array? remove() delete() pop(index) discard() 104 / 106 What will this code output?from array import arrayarr = array("i", [5, 6, 7])arr.append(8)print(arr) array('i', [5, 6, 7, 8]) [5, 6, 7, 8] array([5, 6, 7, 8]) Error 105 / 106 Which method is used to add an element to an array? add() append() insert() push() 106 / 106 What is the purpose of "i" in this line?array("i", [1, 2, 3]) It means the values are floats It defines the array size It means the values are integers It is the array name Your score isThe average score is 78% 0% Restart quiz