1.
Data Types
1. What is the result of 5 + "10" in Python?
o A) 15
o B) Error
o C) 510
o D) 5 + 1 + 0
2. Which of the following is NOT a valid data type in Python?
o A) int
o B) float
o C) char
o D) str
3. Which of the following can you use to check the type of a variable in Python?
o A) type()
o B) var_type()
o C) check()
o D) typeof()
4. Which of the following operations is used to convert a string "123" to an integer?
o A) str(123)
o B) int("123")
o C) float("123")
o D) convert("123")
2. Strings
5. What will be the output of the following code?
6. text = "hello"
7. print([Link]())
o A) hello
o B) HELLO
o C) Hello
o D) [Link]()
8. Which method would you use to remove extra whitespace from both ends of a string?
o A) strip()
o B) remove()
o C) trim()
o D) delete()
9. What is the result of len("Hello, world!")?
o A) 12
o B) 13
o C) 14
o D) 15
3. Lists
8. Which of the following methods adds an item to the end of a list?
o A) add()
o B) append()
o C) insert()
o D) push()
9. What is the index of the first element in a Python list?
o A) 0
o B) 1
o C) -1
o D) None
10. What is the output of the following code?
11. numbers = [1, 2, 3, 4]
12. [Link](3)
13. print(numbers)
o A) [1, 2, 4]
o B) [1, 2, 3, 4]
o C) [2, 3, 4]
o D) [1, 4]
14. Which of the following is the correct way to access the last element in a list named
my_list?
o A) my_list.last()
o B) my_list[0]
o C) my_list[-1]
o D) my_list(end)
4. Loops
12. What will be the output of the following code?
13. for i in range(3):
14. print(i)
o A) 0 1 2
o B) 1 2 3
o C) 0 1 2 3
o D) 0 1
15. Which of the following loops will continue indefinitely?
o A) for i in range(10):
o B) while True:
o C) for i in range(0, -1, -1):
o D) for i in range(1, 5):
16. What is the output of the following code?
17. for i in range(3, 10, 2):
18. print(i)
o A) 3 5 7 9
o B) 3 4 5 6 7 8 9
o C) 3 4 5 6 7
o D) 3 5 7
19. Which loop is best for iterating through all items in a list?
o A) for loop
o B) while loop
o C) do-while loop
o D) repeat-until loop
5. Conditionals
16. What will be the output of the following code?
17. x=5
18. if x > 3:
19. print("Greater")
20. else:
21. print("Smaller")
o A) Smaller
o B) Greater
o C) 5
o D) None
22. Which of the following statements is correct?
o A) if x == 5:
o B) if 5 = x:
o C) if x := 5:
o D) if x => 5:
23. How can you check if a value x is greater than or equal to 5?
o A) if x >= 5:
o B) if x = 5:
o C) if x => 5:
o D) if 5 <= x:
24. Which of the following is used for checking multiple conditions?
o A) if-else
o B) elif
o C) continue
o D) else
6. Functions
20. How do you define a function in Python?
o A) def function_name()
o B) function function_name()
o C) create function_name()
o D) def function_name[]
21. What will be the output of the following code?
22. def greet(name):
23. return f"Hello, {name}"
24.
25. print(greet("Alice"))
o A) Hello
o B) Hello, Alice
o C) Hello, name
o D) greet(Alice)
26. What will happen if you call a function with the wrong number of arguments?
o A) The program will crash
o B) Python will give an error
o C) It will return None
o D) It will return 0
27. Which of the following is a correct way to call a function named multiply with two
arguments x and y?
o A) multiply(x, y)
o B) multiply{x, y}
o C) multiply[x, y]
o D) multiply{x y}
7. Object-Oriented Programming
24. What is the keyword used to create a new class in Python?
o A) class
o B) def
o C) object
o D) new
25. What does the self keyword represent in a method inside a class?
o A) The method name
o B) The instance of the class
o C) The class name
o D) The parent class
26. What is inheritance in Python?
o A) Creating a new object from a class
o B) A method that is inherited from the base class
o C) A process by which one class derives attributes and methods from another class
o D) An error that occurs in classes
27. What will the following code output?
28. class Animal:
29. def speak(self):
30. return "Animal sound"
31.
32. class Dog(Animal):
33. def speak(self):
34. return "Bark"
35.
36. d = Dog()
37. print([Link]())
o A) Animal sound
o B) Bark
o C) None
o D) Error
8. Miscellaneous
28. Which of the following can be used to handle errors in Python?
o A) try-except
o B) for-else
o C) def
o D) catch-finally
29. What is the default value of an uninitialized variable in Python?
o A) None
o B) 0
o C) undefined
o D) null
30. Which of the following is the correct way to create a dictionary in Python?
o A) dict = {"name": "Alice", "age": 25}
o B) dict = ("name": "Alice", "age": 25)
o C) dict = ["name": "Alice", "age": 25]
o D) dict = ("name" => "Alice", "age" => 25)
31. Which method is used to add an item to a Python set?
o A) add()
o B) append()
o C) insert()
o D) push()
32. Which of the following is NOT a valid list operation in Python?
o A) append()
o B) pop()
o C) remove()
o D) delete()
9. Algorithms and Logic
33. Which sorting algorithm does Python use for sorting lists?
o A) Bubble Sort
o B) Merge Sort
o C) Quick Sort
o D) Tim Sort
34. Which Python function is used to find the maximum value in a list?
o A) max()
o B) largest()
o C) maximum()
o D) find_max()
35. What is the time complexity of accessing an element in a Python list by index?
o A) O(1)
o B) O(n)
o C) O(log n)
o D) O(n^2)
10. File I/O
36. What mode should you use to open a file for writing in Python?
o A) r
o B) w
o C) a
o D) rw
37. Which of the following is used to read the contents of a file in Python?
o A) open()
o B) read()
o C) close()
o D) openfile()
38. Which method is used to close an open file in Python?
o A) close()
o B) stop()
o C) end()
o D) finish()
39. Which function is used to open a file in Python?
o A) open()
o B) file_open()
o C) read()
o D) file()
11. Miscellaneous
40. What is the return type of the range() function in Python?
o A) list
o B) tuple
o C) range object
o D) set