Phyton Quiz with Multiple Choice

Take this Python quiz to test your knowledge of Python programming language. Answer multiple-choice questions on topics like syntax, functions, data types, and more. This Python quiz features multiple-choice questions on a variety of topics, including syntax, functions, data types, and more. Test your knowledge of Python programming language and see how you measure up!

Apr 6, 2023 - 16:41
Apr 6, 2023 - 16:44
Phyton Quiz with Multiple Choice

1. What is the output of the following code?

print(3 + 4 * 5)
A. 35
B. 23
C. 50
D. 27

2. What is the correct way to start a Python function?
A. def my_function():
B. function my_function():
C. def function my_function():
D. my_function def():

3. What is the output of the following code?

for i in range(1, 5):
print(i) A. 1 2 3 4
B. 1 2 3
C. 2 3 4
D. 0 1 2 3 4

4. What is the output of the following code snippet?

lst = [1, 2, 3]
lst.append(4)
print(lst)
A. [1, 2, 3]
B. [1, 2, 3, 4]
C. [4]
D. None of the above

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

lst = [1, 2, 3]
lst.pop()
print(lst)

A. [1, 2]
B. [2, 3]
C. [1, 3]
D. [1, 2, 3]

6. What is the output of the following code snippet?

string = 'Hello, World!'
print(string[7:])
A. 'Hello'
B. 'World'
C. 'World!'
D. 'World!Hello'

7. What will be the output of the following code?

x = 3
y = 5
print("x + y =", x + y)
A. x + y = 8
B. x + y = 35
C. x + y = 15
D. x + y = 53

8. What will be the output of the following code?

fruits = ["apple", "banana", "cherry"]
for x in fruits:
    print(x)
A. apple
    banana
    cherry
B. apple, banana, cherry
C. apple banana cherry
D. None of the above

9. What will be the output of the following code?

def say_hello(name):
    print("Hello, " + name)
say_hello("John")
A. Hello, John
B. John
C. Hello
D. None of the above

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

x = [1, 2, 3]
y = x
x.append(4)
print(y)
A. [1, 2, 3]
B. [1, 2, 3, 4]
C. [1, 2, 4]
D. [1, 2, 3, [4]]

11. What is the output of the following code snippet?

x = (1, 2, 3)
y = x
x += (4,)
print(y)
A. (1, 2, 3)
B. (1, 2, 3, 4)
C. (1, 2, 4)
D. (1, 2, 3, [4])

12. What is the output of the following code snippet?

name = 'John'
print(name[-1])
A. J
B. o
C. h
D. n

13. What is the output of the following code snippet?

numbers = [1, 2, 3, 4, 5]
print(numbers[1:3])
A. [1, 2]
B. [2, 3]
C. [3, 4]
D. [2, 3, 4]

14. Which keyword is used to define a function in Python?
A. function
B. def
C. define
D. fun

15. Which keyword is used to exit from a loop? A. exit
B. break
C. continue
D. return

16. What is the output of the following code snippet?

nums = [1, 2, 3, 4, 5]
print(nums[2:4])
A. [1, 2, 3, 4]
B. [2, 3, 4, 5]
C. [3, 4]
D. [4, 5]

17. Which module in Python can be used to create GUI applications? A. tkinter
B. pygame
C. matplotlib
D. pandas

18. What is the output of the following code snippet?

x = ['a', 'b', 'c', 'd']
print(x[-3:])
A. ['a', 'c', 'd']
B. ['c', 'd']
C. ['b', 'c', 'd']
D. ['d', 'c', 'b', 'a']

19. What is the output of the following code snippet?

x = 5
print(f"The value of x is {x}")
A. The value of x is 5
B. The value of x is {x}
C. The value of x is
D. There is a syntax error in the code

20. Which of the following is not a valid Python comment?
A. # This is a comment
B. // This is a comment
C. '''This is a comment'''
D. """This is a comment"""

21. What is the output of the following code snippet?

x = [1, 2, 3]
y = x
x[0] = 4
print(y[0])
A. 1
B. 2
C. 3
D. 4

22. Which of the following is a Python package for scientific computing?
A. Pygame
B. Pygame Zero
C. Pygame No
D. NumPy

23. Which of the following is a loop statement in Python?
A. if
B. else
C. for
D. switch

24. What will be the output of the following code?

x = [1, 2, 3, 4]
print(x[1:3]) A. [2, 3]
B. [1, 2]
C. [1, 2, 3]
D. [3, 4]

25. What is the correct way to open a file for writing in Python?
A. file = open("filename.txt", "r")
B. file = open("filename.txt", "w")
C. file = open("filename.txt", "a")
D. file = open("filename.txt", "x")

26. Which of the following is NOT a Python data type?
A. int
B. str
C. char
D. float

27. Which of the following is not a valid Python data type?
A. list
B. tuple
C. dictionary
D. sequence

28. What is the output of the following code snippet?

print(len('python'))
A. 6
B. 5
C. 4
D. 3

29. Which of the following is not a valid Python loop?
A. while loop
B. for loop
C. do-while loop
D. All of the above are valid Python loops

30. Which of the following is NOT a data type in Python?
A. int
B. double
C. str
D. bool

31. What does the 'range' function in Python return?
A. A list of integers
B. A tuple of integers
C. A range object
D. A generator object

32. What is the output of the following code?

x = 3
y = 5
print(x + y)
A. 8
B. 15
C. "8"
D. "15"

33. What is the output of the following code?

my_list = [1, 2, 3]
my_list.append(4)
print(my_list)
A. [1, 2, 3]
B. [1, 2, 3, 4]
C. [4, 3, 2, 1]
D. [4, 1, 2, 3]

34. Which of the following is not a data type in Python?
A. list
B. dictionary
C. array
D. tuple

35. Which of the following is a built-in function in Python that returns the length of a string?
A. size()
B. len()
C. length()
D. count()

36. What is the result of the following code snippet?

		x = 10
		def func():
		    global x
		    x = 20
		func()
		print(x)
		


A. 10
B. 20
C. Error
D. None of the above

37. What is the output of the following code snippet?

my_list = [1, 2, 3]
my_list.append(4)
print(my_list)
A. [1, 2, 3, 4]
B. [4, 3, 2, 1]
C. [1, 2, 3, 4, 4]
D. [4]

38. Which keyword in Python is used to define a function?
A. define
B. return
C. function
D. def

39. What is the output of the following code snippet?

x = 5
y = 7
print(x + y)
A. 12
B. 35
C. 57
D. 75

40. Which of the following is NOT a valid comparison operator in Python? A. ==
B. !=
C. >
D. >=

41. What is the output of the following code snippet?

for i in range(5):
    print(i)
A. 0 1 2 3 4
B. 1 2 3 4 5
C. 5 4 3 2 1
D. 4 3 2 1 0

42. What is the output of the following code snippet?

x = 10
y = 5
if x % 5 == y:
    print("Hello")
else:
    print("Hi")
A. Hello
B. Hi
C. Hello Hi
D. Hi Hello

43. What is the output of the following code snippet?

def say_hello():
    print("Hello World!")

say_hello()
A. Nothing will be printed
B. Hello
C. World!
D. Hello World!

44. What is the correct way to open a file "file.txt" in Python for reading?
A. open("file.txt", "w")
B. open("file.txt", "r")
C. open("file.txt", "a")
D. open("file.txt", "x")

45. What is the output of the following code snippet?

x = ['ab', 'cd']
y = list(map(list, x))
print(y)
A. [['a', 'b'], ['c', 'd']]
B. ['ab', 'cd']
C. ['a', 'b', 'c', 'd']
D. Error

46. What is the output of the following code snippet?

numbers = [1, 2, 3, 4, 5]
numbers[0] = numbers[4]
numbers[4] = numbers[0]
print(numbers)
A. [5, 2, 3, 4, 1]
B. [1, 2, 3, 4, 5]
C. [1, 2, 3, 4, 1]
D. [5, 2, 3, 4, 5]

47. Which of the following is NOT a valid Python variable name?
A. myVar
B. my_var
C. my-var
D. MyVar

48. What will be the output of the following code snippet?

def sum(a, b):
    return a + b

print(sum(1, '2'))
A. 12
B. '12'
C. TypeError: unsupported operand type(s) for +: 'int' and 'str'
D. None

49. What will be the output of the following code snippet?

num = 2
def multiply(num):
    num = num * 2
multiply(num)
print(num)
A. 2
B. 4
C. None
D. Error

50. Which of the following is a correct syntax to access a value from a dictionary in Python?
A. dict(key)
B. dict[key]
C. dict.get(key)
D. All of the above

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow