Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views2 pages

Tuple Dictionary, Module Set - 2

Uploaded by

krakenvlog01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Tuple Dictionary, Module Set - 2

Uploaded by

krakenvlog01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

SET - 2

1. What will be the output?


t = (1, 2, 3, 2) print(t.count(2))
a) 1 b) 2 c) 3 d) Error
2. Which function is used to convert a list to a tuple?
a) set() b) tuple() c) list() d) convert()
3. What is the output of:
t = (1, 2, (3, 4)) print(t[2][1])
a) 2 b) 3 c) 4 d) Error
4. What will be the output?
t = (1, 2, 3) del t[1] print(t)
a) (1, 3) b) (1, 2, 3) c) Error d) None
5. Which of the following is correct?
a) Tuples use more memory than lists b) Lists are faster than tuples c) Tuples can be keys in
a dictionary
d) Tuples can be modified directly
6. A. Tuples in Python are mutable. B. You can append elements to a tuple using
append().
A. BOTH true B. A true B false C. A false B True D. Both false
7. Assertion (A): You cannot assign a new value to a tuple element.
Reason (R): Tuples are defined to be unchangeable in Python.
A. Both A and R are true, and R is the correct explanation B. A is true, R is false C. A is
false, R is true
D. Both A and R are false
8. Assertion (A): tuple("abc") gives ('a', 'b', 'c').
Reason (R): Strings are iterable, and tuple() converts iterables into tuple items.
A. Both A and R are true, and R is the correct explanation B. A is true, R is false C. A is
false, R is true
D. Both A and R are false
9. Assertion (A): You can store a list inside a tuple.
Reason (R): Tuples can contain mutable and immutable data types.
A. Both A and R are true, and R is the correct explanation B. A is true, R is false C. A is
false, R is true
D. Both A and R are false
10.
Concept Result
A. t = () 1. Empty tuple
B. t = (1, 2, 3)[-1] 2. Returns 3
C. (1,) 3. Tuple with one element
D. (1, 2) + (3,) 4. (1, 2, 3)
E. del t[0] 5. Error (immutability)
A. A3 B2 C1 D4 E5 B. A1 B2 C3 D4 E5 C. A3
B2 C1 D 5 E4 D. A1 B2 C4 D3 E5
11. Can dictionary values be duplicated?
a) No b) Yes c) Only if values are strings d) Only integers
12. How do you iterate through keys and values together?
a) for k in dict: b) for k, v in dict.items() c) for k, v in dict.values()
d) for k, v in dict.keys()
13. What does dict.items() return?
a) List of values b) List of keys c) List of tuples d) Dictionary
14. Which of the following is not allowed in dictionary keys?
a) Integer b) Float c) List d) Tuple
15. What is the result of:
d = {'x': 1, 'y': 2} d['x'] = 10 print(d)
a) {'x': 1, 'y': 2} b) {'x': 10, 'y': 2} c) {'x': 10} d) {'y': 2}
16. Assertion (A): popitem() removes the last inserted key-value pair.
Reason (R): Python 3.7+ dictionaries maintain insertion order.
A. Both A and R are true, and R is the correct explanation B. A is true, R is false C. A is
false, R is true
D. Both A and R are false
17. Assertion (A): Dictionary values can be lists.
Reason (R): Dictionary values can be mutable or immutable.
A. Both A and R are true, and R is the correct explanation B. A is true, R is false C. A is
false, R is true
D. Both A and R are false
18. Assertion (A): You can iterate through a dictionary using .items().
Reason (R): .items() returns key-value pairs as tuples.
A. Both A and R are true, and R is the correct explanation B. A is true, R is false C. A is
false, R is true
D. Both A and R are false
19. A. A dictionary is a mutable data type. B. The clear() method empties the dictionary.
A. BOTH true B. A true B false C. A false B True D. Both false
20. math.floor(5.9) gives:
a) 6 b) 5 c) 4 d) Error
21. Which module provides functions like mean() and median()?
a) math b) statistics c) random d) collections
22. Which of the following functions is not in the math module?
a) cos() b) exp() c) randint() d) log()
23. What is the output of math.pow(2, 3)?
a) 6 b) 8.0 c) 8 d) 9
24. Assertion (A): statistics.mean() returns the arithmetic average.
Reason (R): It adds all values and divides by their count.
A. Both A and R are true, and R is the correct explanation B. A is true, R is false C. A is
false, R is true
D. Both A and R are false
25. Assertion (A): statistics.mode([1,1,2,3]) returns 1.
Reason (R): Mode returns the most frequent value.
A. Both A and R are true, and R is the correct explanation B. A is true, R is false C. A is
false, R is true
D. Both A and R are false

You might also like