Python Online Test

This Python Online Test simulates a real online certification exam. You will be presented with Multiple-Choice Questions (MCQs) based on Python Concepts, where you will be given four options. You will select the best suitable answer for each question and then proceed to the next question without wasting time. You will get your online test score after finishing the complete test.

1. What is the output of the following Python code?

x = 5
y = 3
print(x ** y)
a) 15
b) 125
c) 8
d) 243

2. Which of the following is not a core data type in Python?

a) List
b) Dictionary
c) Class
d) Tuple

3. What does the following Python code snippet return?

def check():
try:
return 'try'
finally:
return 'finally'
print(check())
a) 'try'
b) 'finally'
c) None
d) An error occurs

4. Which of the following is the correct way to add an element to a list in Python?

a) list.add(1)
b) list.append(1)
c) list.insert(1)
d) list.put(1)

5. What is the output of the following Python code?

x = 'abcdef'
i = 'a'
while i in x:
x = x[:-1]
print(x)
a) 'abcdef'
b) 'abcde'
c) 'bcdef'
d) 'abcd'

6. What is the result of the following Python operation 3 * 3**3?

a) 9
b) 27
c) 81
d) 243

7. What does the enumerate function in Python return?

a) A list of tuples
b) An enumerate object
c) A dictionary
d) A set

8. What is the output of the following Python code snippet?

list = [1, 2, 3, 4]
list.insert(2, 5)
print(list)
a) [1, 2, 3, 5, 4]
b) [1, 2, 5, 3, 4]
c) [1, 5, 2, 3, 4]
d) [5, 1, 2, 3, 4]

9. What is the purpose of the pass statement in Python?

a) To declare a variable
b) To exit a loop
c) To act as a placeholder for future code
d) To throw an error

10. What is the output of the following Python code?

def func(a, b=6, c=8):
print(a, b, c)
func(1, 2)
a) 1 6 8
b) 1 2 8
c) 1 2 6
d) 1 6 2

11. What is a correct syntax to output the type of a variable or object in Python?

a) print(typeOf(var))
b) print(type(var))
c) print(typeof var)
d) print(var.type())

12. What will the following Python code print?

x = 0
y = 2
z = len("Python")
x = y > z
print(x)
a) True
b) False
c) 2
d) 6

13. Which operator is used in Python to check if two variables are the same object?

a) ==
b) !=
c) <>
d) is

14. How do you handle exceptions in Python?

a) using try and except blocks
b) using try and catch blocks
c) using do and while blocks
d) using get and post blocks

15. What is the output of the following Python code?

x = True
y = False
z = False
if x or y and z:
print("yes")
else:
print("no")
a) yes
b) no
c) True
d) False

16. What type of object is commonly used to manage data in Python that is derived from dictionaries but provides high-level data manipulation tools?

a) List
b) DataFrame
c) Set
d) Tuple

17. What is the correct way to create a tuple in Python?

a) x = tuple(1, 2, 3)
b) x = (1, 2, 3)
c) x = tuple[1, 2, 3]
d) x = [1, 2, 3]

18. Which function in Python can be used to safely evaluate an expression node or a string containing a Python expression?

a) eval()
b) safe_eval()
c) exec()
d) parse()

19. What will the following Python code output?

print(type(lambda x: x+1))
a) <class 'function'>
b) <class 'method'>
c) <class 'lambda'>
d) <class 'type'>

20. How does Python treat single quotes and double quotes?

a) Differently, with different uses in different contexts
b) The same, both are used to define strings
c) Single quotes are for characters, and double quotes are for strings
d) Neither is used in Python; backticks are used instead

21. What is the result of the expression 4 + 3 % 5 in Python?

a) 7
b) 2
c) 0
d) 1

22. What will happen when the following Python code is executed?

x = [&apos;apple&apos;, &apos;banana&apos;]
y = x
y.append(&apos;cherry&apos;)
print(x)
a) ['apple', 'banana']
b) ['apple', 'banana', 'cherry']
c) ['cherry']
d) An error occurs

23. How can a floating point number be converted to an integer in Python?

a) Using the int() function
b) Using the float() function
c) Using the str() function
d) Using the chr() function

24. What does the following Python code print?

a = [1, 2, 3, 4, 5]
print(a[3:0:-1])
a) [4, 3, 2]
b) [4, 3, 2, 1]
c) [1, 2, 3]
d) []

25. What is the correct way to define a function in Python that takes an arbitrary number of arguments?

a) def func(*args): …
b) def func(**kwargs): …
c) def func(*kwargs): …
d) def func(**args): …

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top