Free Shipping over ₹1199

Python Quiz

Python Quiz

1 / 106

What is the correct file extension for Python files?

2 / 106

Which of the following is a valid variable name in Python?

3 / 106

What is the output of the following code?

print(3 * "hi")

4 / 106

Which keyword is used to define a function in Python?

5 / 106

What will be the output of this code?
x = 5
y = "5"
print(x + int(y))

6 / 106

Which data type is mutable in Python?

7 / 106

What does this code do?
for i in range(3):
print(i)

8 / 106

Which operator is used for exponentiation in Python?

9 / 106

What is the output of type("Hello")?

10 / 106

Which of the following is NOT a Python data type?

11 / 106

Which of the following is a correct way to assign a value to a variable in Python?

12 / 106

What is the result of this code?

x = 3
x += 2
print(x)

13 / 106

Which of the following variables is written using snake_case?

14 / 106

Which of the following variables is written using snake_case?

15 / 106

What will this code output?
a = 5
b = a
a = 10
print(b)

16 / 106

Which keyword is used to declare a variable in Python?

17 / 106

What data type is the variable x after this code?
x = "10"

18 / 106

What is the value of x after this code runs?
x = 7
x = x + 3

19 / 106

Which of the following is NOT a valid variable name?

20 / 106

What will be the output of the following code?
x = 10
y = 5
print(x + y)

21 / 106

Which of the following is a correct way to assign a value to a variable in Python?

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?

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?

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]

28 / 106

Which data type is used to store multiple values in a single variable?

29 / 106

What is the data type of the value True?

30 / 106

Which of these is an example of a string in Python?

31 / 106

What happens when you try to print an undefined variable?
print(score)

32 / 106

Which of these will create an empty list?

33 / 106

What does this code do?
nums = [1, 2, 3]
nums.insert(1, 99)
print(nums)

34 / 106

How can you access the last item in a list?

35 / 106

What is the output of this code?
colors = ["red", "blue", "green"]
print(len(colors))

36 / 106

Which method removes the last item from a list?

37 / 106

What will be the result of this code?
numbers = [10, 20, 30, 40]
numbers[2] = 99
print(numbers)

38 / 106

How do you add an item to the end of a list?

39 / 106

What is the index of the first element in a Python list?

40 / 106

What is the output of this code?
fruits = ["apple", "banana", "cherry"]
print(fruits[1])

41 / 106

Which of the following creates a list in Python?

42 / 106

Which of the following is NOT true about tuples?

43 / 106

What does the index() method do in a tuple?

44 / 106

What is the result of this code?
t = (1, 2, 3, 4)
print(t[-1])

45 / 106

Which method is used to count how many times an item appears in a tuple?

46 / 106

How can you create a tuple with a single value 5?

47 / 106

Which function returns the number of items in a tuple?

48 / 106

What happens when you try to change a value in a tuple?
t = (1, 2, 3)
t[0] = 9

49 / 106

What is the output of this code?
t = (10, 20, 30)
print(t[1])

50 / 106

What is the main difference between a list and a tuple?

51 / 106

How do you create a tuple in Python?

52 / 106

What is the result of this code?
a = {1, 2}
b = {2, 3}
print(a & b)

53 / 106

Which method removes and returns a random element from a set?

54 / 106

What does clear() do in a set?

55 / 106

Which operation finds common elements between two sets?

56 / 106

What will be the result of this code?
a = {1, 2, 3}
b = {3, 4, 5}
print(a.union(b))

57 / 106

What does the discard() method do?

58 / 106

How do you add an element to a set?

59 / 106

What is the output of this code?
s = {1, 2, 2, 3}
print(s)

60 / 106

What is the main feature of a set in Python?

61 / 106

Which of the following creates a set in Python?

62 / 106

Which of the following defines a dictionary in Python?

63 / 106

What is a dictionary in Python?

64 / 106

Which method is used to get the value of a key without an error if the key doesn’t exist?

65 / 106

How do you add a new key-value pair to a dictionary?

66 / 106

What will this code print?
d = {"a": 1, "b": 2}
d["a"] = 3
print(d)

67 / 106

What does the keys() method return?

68 / 106

What is the output of this code?
d = {"x": 100, "y": 200}
print(len(d))

69 / 106

Which operator is used for "or" condition in Python?

70 / 106

What will be printed?

x = 5
if x != 5:
print("Not five")
else:
print("It is five")

71 / 106

What is the result of this code?

x = 10
if x > 5 and x < 15:
print("In range")

72 / 106

What does this code print?
x = 7
if x % 2 == 0:
print("Even")
else:
print("Odd")

73 / 106

What is the output of this code?
x = 3
if x > 5:
print("High")
elif x == 3:
print("Medium")
else:
print("Low")

74 / 106

What keyword is used to check multiple conditions after an if?

75 / 106

What is the output of this code

x = 10
if x > 5:
print("Big")
else:
print("Small")

76 / 106

Which of the following is a correct if statement in Python?

77 / 106

What is the result of this code?
d = {"name": "Bob", "age": 30}
print("age" in d)

78 / 106

Which method removes all items from a dictionary?

79 / 106

Which keyword is used to start a for loop in Python?

80 / 106

What is the output of this code?
for i in range(3):
print(i)

81 / 106

Which keyword starts a while loop in Python?

82 / 106

What does range(5) generate?

83 / 106

What is the output of this code?
for i in range(5):
if i == 3:
continue
print(i)

84 / 106

What is the output of this code?
for i in range(5):
if i == 3:
break
print(i)

85 / 106

What is the use of break in a loop?

86 / 106

How many times will this loop run?
x = 0
while x < 3:
print(x)
x += 1

87 / 106

Which of the following defines a function that takes two parameters?

88 / 106

What is the output of this code?
def greet():
print("Hello!")

greet()

89 / 106

Which keyword is used to define a function in Python?

90 / 106

What does this code print?
count = 0
while count < 2:
print("Hi")
count += 1

91 / 106

Which loop is better when the number of repetitions is unknown?

92 / 106

What is a function with no return value called?

93 / 106

What is the output of this code?
def add(a, b=5):
return a + b

print(add(3))

94 / 106

Which function call is correct for this definition?
def say_hello(name):
print("Hello", name)

95 / 106

What will this code output?
def square(x):
return x * x

print(square(4))

96 / 106

What does a return statement do in a function?

97 / 106

What does this code print?
from array import array
arr = array("i", [10, 20, 30])
print(arr[1])

98 / 106

What is the correct way to create an array of integers in Python using the array module?

99 / 106

Which Python module provides support for arrays?

100 / 106

Can a function return multiple values?

101 / 106

What is the scope of a variable declared inside a function?

102 / 106

Which method returns the index of a value in the array?

103 / 106

How do you remove an element from an array?

104 / 106

What will this code output?
from array import array
arr = array("i", [5, 6, 7])
arr.append(8)
print(arr)

105 / 106

Which method is used to add an element to an array?

106 / 106

What is the purpose of "i" in this line?
array("i", [1, 2, 3])

Your score is

The average score is 100%

0%

    Leave a Reply

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

    Need Help?