Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

Test 2 Python

The document is a Python test with multiple choice, theory, and programming questions about lists, tuples, sets, and dictionaries in Python. The multiple choice section has 15 questions testing knowledge of list indexing and operations, dictionary keys and values, tuple properties, and common methods. The theory section asks to explain the differences between sets and dictionaries, lists and tuples, slicing, and control flow statements. The programming section asks to write code to check for a key in a dictionary, generate a random number, and flatten a nested list.

Uploaded by

techsathish8264
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Test 2 Python

The document is a Python test with multiple choice, theory, and programming questions about lists, tuples, sets, and dictionaries in Python. The multiple choice section has 15 questions testing knowledge of list indexing and operations, dictionary keys and values, tuple properties, and common methods. The theory section asks to explain the differences between sets and dictionaries, lists and tuples, slicing, and control flow statements. The programming section asks to write code to check for a key in a dictionary, generate a random number, and flatten a nested list.

Uploaded by

techsathish8264
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PYTHON TEST 2

LIST, TUPLES, SET , DICTIONARY


TOTAL MARKS : 40
I.MULTIPLE CHOICE QUESTIONS 15 * 1 = 15

1. colors=[“red”,”green”,”pink”,”blue”]
colors[2]
Find output
a. blue b. green
c. pink d. red
2. Which of these will return Chennai from the given list.
Cities=[“Salem”, “Erode”, “Mumbai”, ”Chennai”]
a. Cities( ) b. Cities[3]
b. Cities(3) d. Cities(‘3’)
3. Fruits=[“apple”,”banana”]
Mango in Fruits
a. True b. False
c.true d. false
4. c={1,"hi","well"}
i) d=c.copy()
ii ) d.update(c)
iii ) d=c
identify the correct answer
a) i is correct
b) i,ii correct
c) i and iii are correct
d) all are correct
5. c=["devi","sita"]
c.index("kavitha")
a. name error b. value error c. -1 d. 0
6. Which method returns a new set with all items from
both sets by removing duplicates.
a. union( ) b.append( ) c. extend( ) d. remove ( )
7. Which of these about the dictionary is false

a. The values of a dictionary can be accessed using keys


b. The keys of a dictionary can be accessed using values
c. dictionaries are not ordered
d. dictionaries are mutable
8.To which of the following the “in” operator can be used to
check if an item is in it?
a. Lists
b. Dictionary
c. Tuples
d. All the mentioned above
9. Which of the following will result in an error?
str = “python”
a. print(str1[2])
b. str1[1]= “x”
c. print(str1[0:9])
d. Both (b) & (c)
10. Which of the following will give “Simon” as output?
If str1 = “John, Simon, Aryan”
a. print(str1[-7:-12])
b. print(str1[-11:-7])
c. print(str1[-11:-6])
d. print(str1[-7:-11])
11. What will be the output of the python code?
dict = { ‘c’: 97, ‘a’: 96, ‘b’:98 }
for _ in sorted(dict):
print(dict[_])
a. 96 98 97
b. 96 97 98
c. 98 97 96
d. NameError
12. Which of the following statements given below is/are
true about a python tuple?
a. Tuples have structure, and lists have an order
b. Tuples are homogenous, and lists are heterogenous
c. Tuples are immutable, lists are mutable
d. All of them.
13. If a is a dictionary with some key value pairs, what
does a.popitem( ) do ?
a. removes an arbitrary element
b. removes all the key value pairs
c. removes the key value pair for the key given as an
argument
d. invalid method for dictionary
14. suppose t=(1,2,4,3) which of the following is incorrect?
a. print(t[3])
b. t[3]=45
c. print(max(t))
d. print(len(t))
15. t1=(1,2,3,4)
t2=(1,2,4,3)
t1<t2
what will be the output?
a. True b.False c.Error d.none
II. THEORY QUESTIONS 10
1. Difference between a Set and Dictionary.
2. Difference between List and Tuples.
3. What is Slicing in Python?
4. What is Break, Continue and Pass in Python?
5. What is the difference between extend and append ?

III. PROGRAM WRITING 15


1. Python program to check if a key is already present in
a Dictionary.
2. Python program to generate a Random Number
3. Python program to flatten a Nested List.

You might also like