1. What is the output of the following code?
Python Code
x = [1, 2, 3, 4]
print(x[-1])
A) 1
B) 2
C) 3
D) 4
Answer: D) 4
2. Which of the following data types is immutable inPython?
A) List
B) Dictionary
C) Tuple
D) Set
Answer: C) Tuple
3. Which keyword is used to define a function in Python?
A) func
B) define
C) def
D) lambda
Answer: C) def
4. What is the output of the following code?
python code
x = "Python"
print(x[1:4])
A) Py
B) Pyt
C) ytho
D) yth
Answer: D) yth
5. Which of the following is a correct way to create aset in Python?
A) s = {}
B) s = {1, 2, 3}
C) s = set[]
D) s = ()
Answer: B) s = {1, 2, 3}
6. What is the purpose of the pass statement in Python?
A) To skip the current iteration of a loop
B) To exit a function
C) To do nothing and allow the program to continue
D) To break out of a loop
Answer: C) To do nothing and allow the program tocontinue
7. Which method is used to remove the last element from alist in Python?
A) remove()
B) delete()
C) pop()
D) discard()
Answer: C) pop()
8. What will the following code print?
python code
print(2 ** 3)
A) 6
B) 8
C) 9
D) 12
Answer: B) 8
9. Which of the following loops is supported by Python?
A) for
B) while
C) do-while
D) Both A and B
Answer: D) Both A and B
10. How do you create a dictionary in Python?
A) d = [1: 'apple', 2: 'banana']
B) d = {1: 'apple', 2: 'banana'}
C) d = {1, 2, 3}
D) d = (1, 2, 3)
Answer: B) d = {1: 'apple', 2: 'banana'}