Basic Level
1. Which of the following is the correct way to create a list in Python?
o A) my_list = (1, 2, 3)
o B) my_list = [1, 2, 3]
o C) my_list = {1, 2, 3}
o D) my_list = <1, 2, 3>
2. What is the output of the expression print(2 ** 3) ?
o A) 6
o B) 8
o C) 9
o D) 5
3. Which keyword is used to define a function in Python?
o A) func
o B) function
o C) def
o D) define
4. How do you start a single-line comment in Python?
o A) // This is a comment
o B) /* This is a comment */
o C) # This is a comment
o D) <!-- This is a comment -->
5. What is the correct way to import the NumPy library using its standard
alias?
o A) import numpy as nump
o B) import numpy as np
o C) from numpy import np
o D) import np from numpy
6. What does the len() function do when applied to a string?
o A) Converts the string to lowercase
o B) Returns the total number of characters in the string
o C) Deletes the string from memory
o D) Counts only the vowels in the string
7. Which data structure in Python stores elements as key-value pairs?
o A) List
o B) Tuple
o C) Dictionary
o D) Set
8. Given x = "Python" , what is the result of print(x[0]) ?
o A) P
o B) n
o C) y
o D) Error
9. What is the purpose of the range(5) function when used in a loop?
o A) Generates a sequence of numbers from 1 to 5
o B) Generates a sequence of numbers from 0 to 4
o C) Generates 5 random numbers
o D) Multiplies a number by 5
10. Which statement is used to exit a loop early before its condition
is fully met?
o A) continue
o B) exit
o C) stop
o D) break
11. What will be the output of type(3.14) ?
o A) <class 'int'>
o B) <class 'str'>
o C) <class 'float'>
o D) <class 'double'>
12. How do you append an element x to the end of a list named
my_list ?
o A) my_list.add(x)
o B) my_list.append(x)
o C) my_list.push(x)
o D) my_list.insert(x)
13. What is the output of print(10 % 3) ?
o A) 1
o B) 3
o C) 0.33
o D) 0
Intermediate Level
1. What is the main structural difference between a List and a Tuple in
Python?
o A) Lists are faster than tuples.
o B) Lists are mutable (can be changed), while tuples are
immutable (cannot be changed).
o C) Tuples can only store numbers, while lists can store text.
o D) Lists use parentheses () , and tuples use brackets [] .
2. What is the output of the following code snippet?
3. nums = [10, 20, 30, 40, 50]
4. print(nums[1:4])
o A) [10, 20, 30]
o B) [20, 30, 40]
o C) [20, 30, 40, 50]
o D) [30, 40, 50]
5. Which of the following is a valid list comprehension that squares
every number in old_list ?
o A) new_list = [x*x for x in old_list]
o B) new_list = for x in old_list print(x*x)
o C) new_list = [x^2 while x in old_list]
o D) new_list = {x**2 for x in old_list}
6. What does the zip() function do in Python?
o A) Compresses a file to reduce its size
o B) Iterates over multiple iterables in parallel, pairing matching
elements together
o C) Sorts a list in ascending order
o D) Unzips a compressed folder structure
7. In Object-Oriented Python, what is the role of the __init__ method?
o A) To delete an object instance from memory
o B) To initialize a class instance's attributes when an object is
created
o C) To inherit attributes from a parent class automatically
o D) To convert an object into an integer format
8. How do you safely catch an exception or error in Python to prevent a
crash?
o A) Using if and else blocks
o B) Using try and except blocks
o C) Using catch and throw blocks
o D) Using error and resume blocks
9. What is the difference between the / operator and the // operator?
o A) / multiplies numbers, while // divides them.
o B) / performs standard float division, while // performs floor
(integer) division.
o C) / is for integers, while // is for text strings.
o D) There is no difference; they perform the exact same task.
10. Which NumPy attribute is commonly used to find the
dimensions/shape of an array?
o A) [Link]()
o B) [Link]
o C) [Link]
o D) [Link]()
11. What does a function return if it does not have an explicit return
statement?
o A) 0
o B) False
o C) None
o D) An empty string ""
12. Which of the following methods removes all elements from a
dictionary named my_dict ?
o A) my_dict.remove()
o B) my_dict.clear()
o C) my_dict.delete()
o D) my_dict.flush()
13. What happens when you try to add a duplicate element to a
Python Set?
o A) An IdError is raised.
o B) The set automatically overwrites the entire collection.
o C) The duplicate element is ignored, as sets only store unique
values.
o D) The duplicate element replaces the original element at index
0.
14. What is the output of the expression print("a" + "b" * 2) ?
o A) abab
o B) abb
o C) a2b2
o D) TypeError