Page 16 - PYTHON-12
P. 16
5. What will be the output of the following code? (1)
s = "Data Science"
print(s[:4][::-1])
(a) D (b) Data
(c) Cs (d) ataD
Ans. (d) ataD
6. Identify the output of the following code. (1)
dictt = {'name': 'Alina', 'age': 30, 'city': 'Hyderabad'}
print(dictt.get('country', 'Not Found'))
(a) Alina
(b) Hyderabad
(c) Not Found
(d) 30
Ans. (c) Not Found
7. What will be the output of the following code? (1)
def divide(x, y):
try:
result = x / y
except ZeroDivisionError:
print("Division by zero error")
finally:
print("Operation complete")
divide(10, 0)
(a) Division by zero error
(b) Operation complete
(c) Division by zero error
Operation complete
(d) Error
Ans. (c) Division by zero error
Operation complete
8. What does pop() method do in a list if no index is specified? (1)
(a) Removes the first element from the list
(b) Removes the last element from the list
(c) Removes all the elements from the list
(d) Removes an element from the list based on a condition
Ans. (b) Removes the last element from the list
9. In a relational database, what happens when a primary key that is referenced by a foreign key in another
table is updated? (1)
(a) The referenced foreign key values in the other table are automatically updated to match.
(b) All related records in the referencing table are deleted.
(c) The update fails if the database enforces referential integrity.
(d) The primary key is updated but the foreign key values remain unchanged.
Ans. (c) The update fails if the database enforces referential integrity.
A.2 Computer Science–XII