CH 2 - Revision Tour 2 Practice Material For Board Exam - Updated
CH 2 - Revision Tour 2 Practice Material For Board Exam - Updated
PRACTICE QUESTIONS
STATE TRUE OR FALSE
1. String is mutable data type.
2. Python considered the character enclosed in triple quotes
w
as String.
I
ra
3. String traversal can be done using „for‟ loop only.
pI
4. Strings have both positive and negative indexes.
xR
5. The find() and index() are similar functions.
_N
6. Indexing of string in python starts from 1.
om
cw
7. The Python strip() method removes any spaces or specified
.c
characters at the start and end of a string.
W
8.
se
The startswith() string method checks whether a string
fe
cb
R
starts with a particular substring.
n4
9.
6p
"The characters of string will have two-way indexing."
ho
s-
ASSERTION & REASONING
st
yt
place.
ne
e
ha
/c
w
3. A: a=‟3‟
m
b=‟2‟
co
c=a+b
e.
4. A:
o
a = "Hello"
.y
w
b = "llo"
w
c=a-b
w
print(c)
://
5. A:
str1="Hello" and str1="World" then print(str1*3) will give
error.
R : * replicates the string hence correct output will be
HelloHelloHello
w
8. A: Function isalnum() is used to check whether characters
I
ra
in the string are alphabets or numbers.
pI
R: Function isalnum() returns false if it either contains
xR
alphabets or numbers
_N
9. A: The indexes of a string in python is both forward and
om
backward.
cw
R: Forward index is from 0 to (length-1) and backward
.c
W
se
index
fe
is from -1 to (-length)
cb
R
10. A: The title() function in python is used to convert the first
n4
6p
character in each word to Uppercase and remaining
ho
s-
characters to Lowercase in the string and returns an
st
yt
updated string.
C
np
l/U
ha
w
the result?
m
co
limits. If it is then:
w
values
ht
w
6. Predict the output of the following code:
I
ra
RS=''
pI
S="important"
xR
for i in S:
_N
RS=i+RS
om
print(RS)
cw
7. What will the following code print?
.c
W
se
>>> print(max("zoo 145 com"))
fe
(a) 145 (b) 122 (c) z (d) zoo
cb
R
8. Ms. Hetvee is working on a string program. She wants to
n4
6p
display last four characters of a string object named s.
ho
s-
Which of the following is statement is true?
st
yt
l/U
msg [ : : -1]
.L
ha
w
(a) str[ : : -6] (b) str[ : : -1][ : : -6] (c) str[ : :6] (d) str[0] + str[-
1]
e.
ub
(a) state [-5:] (b) state [4:] (c) state [:4] (d) state [:-4]
w
during execution?
w
://
S=["CBSE"] # Statement 1
s
S+="Delhi" # Statement 2
tp
w
n = "Post on Twitter is trending"
I
ra
q = n.split('t')
pI
print( q[0]+q[2]+q[3]+q[4][1:] )
xR
(a)Pos on witter is rending (b)Pos on Twitter is ending
(c) Poser witter is ending (d) Poser is ending
_N
om
15. What will be the result of the following command:-
cw
>>>"i love python".capitalize()
.c
W
se
(a) 'I Love Python' (b) 'I love python'
fe
(c) 'I LOVE PYTHON' (d) None of the above
cb
R
16. The number of element return from the partition function
n4
6p
is: >>>"I love to study Java".partition("study")
ho
s-
(a) 1 (b) 3 (c) 4 (d) 5
st
yt
l/U
S='INDIAN'
ar
L=S.partition('N')
ne
e
print(G)
w
ha
w
>>>string.find("fox",9,34)
e.
X="abcdef"
o
.y
i='a'
w
while i in X:
w
S1="Computer2023"
ht
S2="2023"
print(S1.isdigit(), S2.isdigit())
a)False True b) False False
c) True False d) True True
w
a = a.split('a')
I
ra
b = a[0] + "-" + a[1] + "-" + a[3]
pI
print (b)
xR
a) Year – 0- at All the best b) Ye-r 2022 -ll the best
c) Year – 022- at All the best d) Year – 0- at all the best
_N
om
23. Select the correct output of the code:
cw
mystr = „Python programming is fun!‟
.c
W
se
mystr = mystr.partition('pro')
fe
mystr='$'.join(mystr)
cb
R
(a) Python $programming is fun!
n4
s-
(c) Python$ pro$ gramming is fun!$
st
yt
s="Good Morning"
ne
e
ha
w
Str1="Hello World"
ub
Str1.replace('o','*')
ut
Str1.replace('o','*')
o
.y
returns true.
tp
S="Hello World!"
print(S.find("Hello"))
(a) 0 (b) 3 (c) [2,3,7] (d) (2,3,7)
28. Which of the following is not a valid Python String
operation?
(a) 'Welcome'+'10' (b)'Welcome'*10
(c) 'Welcome'*10.0 (d) '10'+'Welcome'
By: Amjad Khan Website: https://www.learnpython4cbse.com/ Page 6 of 32
YouTube: https://www.youtube.com/channel/UCsts-6pRfeWcw_NxRpIraIw
29. Which of the following statement(s) would give an error
after executing the following code?
EM = "Blue Tick will cost $8" # Statement 1
print( EM) # Statement 2
ME = "Nothing costs more than Truth" # Statement 3
EM *= 2 # Statement 4
EM [-1: -3 : -1] += ME[ : 7] # Statement 5
(a) Statement 3 (b) Statement 4
w
(c) Statement 5 (d) Statement 4 and 5
I
ra
30. Select the correct output of the following code :
pI
s="I#N#F#O#R#M#A#T#I#C#S"
xR
L=list(s.split("#"))
print(L)
_N
om
(a) [I#N#F#O#R#M#A#T#I#C#S]
cw
(b) [„I‟, „N‟, „F‟, „O‟, „R‟, „M‟, „A‟, „T‟, „I‟, „C‟, „S‟]
.c
W
(c) ['I N F O R M A T I C S']
se
fe
(d) ['INFORMATICS']
cb
R
31. STRING="WELCOME" #Line1
n4
s-
for S in range[0,8] #Line3
st
yt
print(STRING[S]) #Line4
C
np
ha
w
lowercase.
co
s = input("Enter a string")
e.
s = s.lower()
ub
for c in ',.;:-?!()\'"':
ut
_________________
o
.y
print(s)
w
i am what i am
w
w
3. Consider the given Python string declaration:
I
ra
>>> mystring = 'Programming is Fun'
pI
>>> printmystring[-50:10:2].swapcase())
xR
4. Rewrite the following:
_N
STRING=""WELCOME
om
NOTE = " "
cw
for S in range(0,8):
.c
W
se
if STRING[S]= ‟E‟:
fe
print(STRING(S))
cb
R
Else:
n4
print "NO" 6p
ho
s-
5. Given is a Python string declaration:
st
yt
l/U
Name = "cBsE@2051"
.L
R=" "
w
ha
w
if Name[x].isupper ( ):
m
co
R = R + Name[x].lower()
elif Name[x].islower():
e.
R = R + Name[x].upper()
ub
elif Name[x].isdigit():
ut
R = R + Name[x-1]
o
.y
else:
w
R = R + "#"
w
print(R)
w
://
w
Msg3=Msg3+Msg2[I]
I
ra
else:
pI
Msg3=Msg3+"*"
xR
print(Msg3)
8. Predict the output of the following:
_N
om
s="3 & Four"
cw
n = len(s)
.c
W
m=""
se
fe
for i in range(0, n):
cb
R
if (s[i] >= 'A' and s[i] <= 'Z'):
n4
m = m +s[i].upper() 6p
ho
s-
elif (s[i] >= 'a' and s[i] <= 'z'):
st
yt
m = m +s[i-1]
C
np
if (s[i].isdigit()):
l/U
ar
m = m + s[i].lower()
ne
e
else:
.L
m = m +'-'
w
ha
print(m)
w
/c
w
9. Name="PythoN3.1"
m
R=" "
co
for x in range(len(Name)):
e.
if Name[x].isupper():
ub
R=R+Name[x].lower()
ut
elif Name[x].islower():
o
.y
R=R+Name[x].upper()
w
elif Name[x].isdigit():
w
R=R+Name[x-1]
w
else:
://
R=R+"#"
s
tp
print(R)
ht
w
else:
I
ra
count+=1
pI
break
xR
print(string)
print(count)
_N
om
11. Write the output of the code snippet.
cw
txt = "Time, will it come back?"
.c
W
x = txt.find(",")
se
fe
y = txt.find("?")
cb
R
print(txt[x+2:y])
n4
s-
S='Python Programming'
st
yt
L=S.split()
C
np
S=','.join(L)
l/U
ar
print(S)
ne
e
ha
w
L=S.split()
/c
w
for W in L:
m
if W.lower()==W[::-1].lower()
co
print(W)
e.
ub
*********************************************************
o ut
.y
w
w
w
://
s
tp
ht
w
7. Sort() and sorted() both are similar function.
I
ra
8. l1=[5,7,9,4,12] 5 not in l1
pI
9. List can be extend
xR
10. Mutable means only we can insert elements
_N
11. Index of last element in list is n-1, where n is total number
om
cw
of elements.
.c
12. We can concatenate only two list at one time.
W
13.
se
L.pop() method will return deleted element immediately
fe
cb
R
14. L.insert() method insert a new element at the beginning of
n4
s-
15. If index is not found in insert() I.e. L.insert(102,89) then it
st
C
np
ne
ha
the list.
w
/c
19. L.clear() used to clear the elements of the list but memory
w
20. L.append() append more than one element at the end of the
e.
list.
ub
21. L=[10,20,30]
ut
L.extend([90,100])
o
print(L)
.y
w
[10,20,30,[90,100]]
w
w
a=[10,20]
I
ra
b=a[:]
pI
print( a is b)
xR
R: "is" is used for checking whether or not both the
_N
operands is using same memory location
om
5. A: list() is used to convert string in to list element
cw
R: string will be passed into list() it will be converted into
.c
W
se
list elements
fe
cb
6. A: reverse() is used to reverse the list elements.
R
Reason: it can reverse immutable data type
n4
elements also 6p
ho
s-
7. A: pop() can delete elements from the last index of list
st
yt
l/U
only.
ar
n
w
ha
type.
w
beginning.
w
only.
://
11. A: Anu wants to delete the elements from the list using
s
pop() function.
tp
w
L[-2::-1]?
I
ra
(a) [6, 9, 18, 7] (b) [6,1] (c) [6,9,18] (d) [6]
pI
4. If a List L=['Hello','World!'] Identify the correct output of the
xR
following Python command: >>> print(*L)
_N
(a) Hello World! (b) Hello,World!
om
(c)'Hello','World!' (d) 'Hello','World!'
cw
5. Consider the list aList=[ "SIPO", [1,3,5,7]]. What would the
.c
W
se
following code print?
fe
cb
(a) S, 3 (b) S, 1 (c) I, 3 (d) I, 1
R
6. Suppose list1 is [1, 3, 2], What is list1 * 2 ?
n4
a) [2, 6, 4] 6p
(b) [1, 3, 2, 1, 3]
ho
s-
(c) [1, 3, 2, 1, 3, 2] (d) [1, 3, 2, 3, 2, 1]
st
yt
l/U
a) [0, 1, 2, 3] b) [0, 1, 2, 3, 4]
ar
8. >>> L1=[6,4,2,9,7]
.L
n
w
ha
10. Which one is the correct output for the following code?
w
a=[1,2,3,4]
w
w
b=[sum(a[0:x+1])
://
for x in range(0,len(a)):
s
print (b)
tp
11. What will be the output for the following python code:
L=[10,20,30,40,50]
L=L+5
print(L)
(a) [10,20,30,40,50,5] (b) [15,25,35,45,55]
(c) [5,10,20,30,40,50] (d) Error
w
(d) [ ] @ [78, 45, 36, 23, 10]
I
ra
13. The append() method adds an element at
pI
(a) First (b) Last (c) Specified index (d) At any
xR
location
_N
14. The return type of x in the below code is
om
txt = "I could eat bananas all day"
cw
x = txt.partition("bananas")
.c
W
se
(a) string (b) List (c) Tuple (d) Dictionary
fe
15. S1: Operator + concatenates one list to the end of another
cb
R
list.
n4
6p
S2: Operator * is to multiply the elements inside the list.
ho
s-
Which option is correct?
st
yt
ha
w
method?
/c
w
a=[1,2,3,4,5]
o
(a) 5 5 1 2 3 (b) 5 1 2 3 4
.y
for i in range(1,5):
w
a[i-1]=a[i]
w
print(a[i],end=" ")
s
tp
min(max(False,-3,-4),2,7)
(a) -3 (b) -4 (c) True (d) False
w
L=[3,3,2,2,1,1]
I
ra
L.append(L.pop(L.pop()))
pI
print(L)
xR
(a) [3,2,2,1,3] (b)[3,3,2,2,3] (c)[1,3,2,2,1] (d)[1,1,2,2,3,3]
_N
21. Predict the output of the following:
om
L1=[1,4,3,2]
cw
L2=L1
.c
W
se
L1.sort()
fe
print(L2)
cb
R
(a) [1,4,3,2] (b)[1,2,3,4] (c) 1 4 3 2 (d) 1 2 3 4
n4
s-
PL=['Basic','C','C++']
st
yt
PL.sort(reverse=True) ?
l/U
ar
ha
w
Statement 1: list1.reverse()
/c
w
Statement 2: list1[::-1]
m
25. How would you create a loop to iterate over the contents of
w
://
the list given as Days = [31, 28, 31, 30, 31, 30, 31, 31,30]
s
print(days)
(b) for days in Days:
print(days)
(c) for days in range(len(Days)):
print(days)
(d) for days in Days:
print(monthDays)
w
L1.extend(L2)
I
ra
L1.append(L3)
pI
print(L1)
xR
(a) [1,2,3,4,5,6,7] (b)[1,2,3,[4,5],6,7]
(c) [1,2,3,4,5,[6,7]] (d)[1,2,3,[4,5],[6,7]]
_N
om
27. State True or False "There is no conceptual limit to the size
cw
of a list."
.c
W
se
28. The statement del l[1:3] do which of the following task?
fe
a. deletes elements 2 to 4 elements from the list
cb
R
b. deletes 2nd and 3rd element from the list
n4
6p
c. deletes 1st and 3rd element from the list
ho
s-
d. deletes 1st, 2nd and 3rd element from the list
st
yt
29. Which of the following will give output as: [23, 2, 9, 75]?
C
np
l/U
If list1=[6,23,3,2,0,9,8,75]
ar
ha
w
row.sort()
co
print()
ut
followed by 33 6 1 2
w
followed by 33 6 1 2
s
followed by 1 2 6 33
ht
w
lst1=[10,15,20,25,30]
I
ra
lst1.insert(3,4)
pI
lst1.insert(2,3)
xR
print(lis[-5])
_N
3. Write output for the following code:
om
list1=[x+2 for x in range(5)]
cw
print(list1)
.c
W
se
4. What will be the output of the following code?
fe
a=[1,2,3,4]
cb
R
s=0
n4
for a[-1] in a: 6p
ho
s-
print(a[-1])
st
yt
s+=a[-1]
C
np
l/U
print(„sum=‟,s)
ar
(i) L=[10,20]
.L
L1=[30,40]
w
ha
w
L2=[50,60]
/c
w
L.append(L1)
m
L.extend(L2)
co
print(L)
e.
Q=M
o
.y
M[2]+=22
w
L=len(M)
w
l=[ ]
ht
for i in range(4):
l.append(2*i+1)
print(l[::-1])
w
CNT-=1
I
ra
8. Write the output of the following:
pI
x = [[1, 2, 3],[4, 5, 6],[7, 8, 9]]
xR
result = []
for items in x:
_N
om
for item in items:
cw
if item % 2 == 0:
.c
W
result.append(item)
se
fe
print(result)
cb
R
9. Write the output of the following python code:
n4
Numbers =[9,18,27,36] 6p
ho
s-
for num in Numbers:
st
yt
for N in range(1,num%8):
C
np
print(N,"$",end="")
l/U
ar
print()
ne
e
List1 = list("Examination")
w
ha
w
List2 =List1[1:-1]
/c
w
new_list = []
m
for i in List2:
co
j=List2.index(i)
e.
if j%2==0:
ub
List1.remove(i)
ut
print(List1)
o
.y
fruit_list2 = fruit_list1
w
fruit_list3 = fruit_list1[:]
://
s
fruit_list2[0] = 'Guava'
tp
fruit_list3[1] = 'Kiwi'
ht
sum = 0
for ls in (fruit_list1, fruit_list2, fruit_list3):
if ls[0] == 'Guava':
sum += 1
if ls[1] == 'Kiwi':
sum += 20
print(sum)
w
for i in L1:
I
ra
if i not in L2:
pI
L2.append(i)
xR
print(L1,L2,sep='$')
_N
15. Predict the output of the following:
om
num=[10,20,30,40,50,60]
cw
for x in range(0,len(num),2):
.c
W
se
num[x], num[x+1]=num[x+1], num[x]
fe
print(num)
cb
R
16. Predict the output of the following:
n4
L=[1,2,3,4,5] 6p
ho
s-
Lst=[]
st
yt
for i in range(len(L)):
C
np
if i%2==1:
l/U
ar
t=(L[i],L[i]**2)
ne
e
Lst.append(t)
.L
print(Lst)
w
ha
w
del sub[2]
co
sub.remove("ENG")
e.
sub.pop(1)
ub
print(sub)
ut
print(list1[-4:0:-1])
w
://
L=[10,20,40,50,60,67]
tp
L[0:3]="100"
ht
print(L)
w
L.sort(reverse=True)
I
ra
S=L.pop(2)
pI
L.insert(4,89)
xR
L.sort()
L.remove(90)
_N
om
print(L)
cw
22. Predict the output of the following:
.c
W
se
L=[10,2,5,-1,90,23,45]
fe
L.sort(reverse=True)
cb
R
G=L.append(L.pop(L.pop()))
n4
print(G) 6p
ho
s-
23. Predict the output of the following:
st
yt
L=['30','40','20','50']
C
np
count=3
l/U
ar
Sum=0
ne
e
P=[]
.L
for i in[6,4,5,8]:
w
ha
w
T=L[count]
/c
w
Sum=float(T)+i
m
P.append(Sum)
co
count-=1
e.
print(P)
ub
print(P[3:0:-1])
ut
for i in[0,1,2,3]:
o
.y
P[i]=int(P[i])+10
w
print(P)
w
L=['FORTRAN','C++','Java','Python']
://
s
L.insert(2,"HTML")
tp
del L[4]
ht
L.remove('Java')
L.pop()
L.insert(1,"PHP")
L.sort()
L.pop()
print(L)
*********************************************************
By: Amjad Khan Website: https://www.learnpython4cbse.com/ Page 20 of 32
YouTube: https://www.youtube.com/channel/UCsts-6pRfeWcw_NxRpIraIw
TOPIC - TUPLES
STATE TRUE OR FALSE
1. Tuple data structure is mutable
2. tuples allowed to have mixed lengths.
3. tuple have one element for Ex: S=(10)
4. We Can concatenate tuples.
5. The elements of the of a tuple can be deleted
6. A tuple storing other tuples is called as nested tuple
w
7. The + Operator adds one tuple to the end of another tuple
I
ra
8. A tuple can only have positive indexing.
pI
ASSERTION & REASONING
xR
1. A: Tuples are ordered
_N
R: Items in a tuple has an defined order that will not be
om
cw
changed.
.c
2. A: A tuple can be concatenated to a list, but a list cannot
W
be concatenated to a tuple.
se
fe
cb
R
R: Lists are mutable and tuples are immutable in Python
n4
s-
R: Tuple data structure is created by the programmers and
st
C
np
4. a=(1,2,3)
l/U
a[0]=4
ar
ne
ha
/c
>> tuple1.index(90)
ub
print(T1.index(x))
w
8. >>>tuple1 = (10,20,30,40,50,60,70,80)
ht
>>>tuple1[2:]
Output: (30, 40, 50, 60, 70, 80)
A: Output given is incorrect
R: Slicing in above case ends at last index
w
comma.
I
ra
OBJECTIVE TYPE QUESTIONS (MCQ)
pI
1. Which of the following statement creates a tuple?
xR
a) t=[1,2,3,4] b) t={1,2,3,4} c) t=<1,2,3,4> d)
_N
t=(1,2,3,4)
om
cw
2. Which of the following operation is supported in python
.c
with respect to tuple t?
W
se
a) t[1]=33 b) t.append(33) c) t=t+t d) t.sum()
fe
cb
3. Which of the following is not a supported operation in
R
n4
6p
Python?
(a) “xyz”+ “abc” (b) (2)+(3,) (c) 2+3 (d) [2,4]+[1,2]
ho
s-
4. Predict the output:
st
yt
T=('1')
np
l/U
print(T*3)
ar
ha
MyTuple1=(1, 2, 3) #Statement1
w
/c
MyTuple2=(4) #Statement2
w
MyTuple1.append(4) #Statement3
co
t1=(2,3,4,5,6)
s
print(t1.index(4))
tp
ht
w
9. What will be the output for the following Python
I
ra
statement?
pI
T=(10,20,[30,40,50],60,70)
xR
T[2][1]=100
_N
print(T)
om
(a) (10,20,100,60,70) (b) 10,20,[30,100,50],60,70)
cw
.c
(c) (10,20,[100,40,50],60,70) (d) None of these
W
se
10. Which of the following is an unordered collection of
fe
cb
elements
R
(a) List (b) Tuple (c) Dictionary (d) String
n4
11. 6p
Consider the following statements in Python and the
ho
s-
question that follows:
st
yt
l/U
n
w
ha
following is incorrect ?
.y
min(T))
w
w
T=('A','B','C')
s
w
T2=T1 * 2
I
ra
print(len(T2))
pI
(a) 0 (b) 2 (c) 1 (d) Error
xR
19. Predict the output:
_N
Tup=(3,1,2,4)
om
sorted(Tup)
cw
.c
print(Tup)
W
se
(a) (3,1,2,4) (b) (1,2,3,4) (c) [3,1,2,4] (d) [1,2,3,4]
fe
cb
20. Predict the output of the following:
R
n4
S=([1,2],[3,4],[5,6])
S[2][1]=8 6p
ho
s-
print(T)
st
yt
(a) ([1,2],[8,4],[5,6])
np
l/U
(b) ([1,2],[3,4],[8,6])
ar
(c) ([1,2],[3,4],[5,8])
ne
e
.L
ha
w
/c
w
m
co
e.
ub
out
.y
w
w
w
s://
tp
ht
w
list1.insert(2,8)
I
ra
list1.pop()
pI
tuple1=tuple(list1)
xR
print(tuple1)
_N
3. Predict the output of the following code:
om
tuple1 = ( [7,6], [4,4], [5,9] , [3,4] , [5,5] , [6,2] , [8,4])
cw
.c
listy = list( tuple1)
W
se
new_list = list()
fe
cb
for elem in listy :
R
tot = 0
n4
s-
tot += value
st
yt
if elem.count(value) == 2:
C
np
l/U
new_list.append(value)
ar
tot = 0
ne
e
else:
.L
n
w
ha
print( tuple(new_list) )
w
a,b,c,d = (1,2,3,4)
co
mytuple = (a,b,c,d)*2+(5**2,)
print(len(mytuple)+2)
e.
ub
******************************************************
o
.y
w
w
w
://
s
tp
ht
w
dictionary.
I
ra
6. D.get() method is used to insert new key:value pair inside
pI
of the dictionary.
xR
ASSERTION & REASONING
_N
1. A: Dictionaries are mutable.
om
R: Individual elements can be changed in dictionary in
cw
.c
place.
W
se
2. A: Dictionary in Python holds data items in key-value pairs
fe
cb
R: Immutable means they cannot be changed after
R
creation.
n4
s-
R: Dictionary Key‟s are immutable.
st
yt
l/U
in { }.
n
w
ha
format.
/c
w
del keyword.
o
w
a) <key> in <dictionary_obj>
I
ra
b) <key> not in <dictionary_obj>
pI
c) <key> found in <dictionary_obj>
xR
d) a) <key> exists in <dictionary_obj>
_N
3. What will be the output for the following Python statements?
om
D= {“Amit”:90, “Reshma”:96, “Suhail”:92, “John”:95}
cw
.c
print(“John” in D, 90 in D, sep= “#”)
W
se
(a) True#False (b)True#True (c) False#True (d) False#False
fe
cb
4. Choose the most correct statement among the following –
R
n4
s-
(c) a dictionary is a sequential collection of elements key-
st
yt
value pairs
np
l/U
d1={1:2,3:4,5:6}
n
w
ha
d2=d1.popitem()
w
print(d2)
/c
w
a) d = { } b) d = {"john":40, "peter":45}
ub
for i in d:
w
print (i)
w
w
D={1:"One",2:"Two",3:"Three"}
s
L=[ ]
tp
ht
w
d. None of the above
I
ra
10. D={'A':1, 'B':2, 'C':3}
pI
Then, which of the following command will remove the
xR
entire dictionary from the memory?
_N
(a) del(D) (b) D.del() (c) D.clear() (d) D.remove()
om
11. Predict the output of the following:
cw
.c
D1={'A':5,'B':5,'C':9,'D':10}
W
se
D2={'B':5,'D':10}
fe
cb
D1.update(D2)
R
print(D1)
n4
6p
(a) {'A':5,'B':5,'C':9,'D':10} (b) {'A':5,'B':5,'C':9,'B':5,'D':10}
ho
s-
(c) {'A':5,'C':9,'D':10} (d) {'B':7,'D':10,'A':5,'C':9}
st
yt
l/U
D1={1:2,2:3,3:4}
ar
D2=D1.get(1,2)
ne
e
print(D2)
.L
n
w
ha
Dictionary?
co
(d) Replication
ub
D2={1:10,4:56,45:100}
.y
print(D1==D2)
w
D1={1:10,4:56,100:45}
tp
D2={1:10,4:56,45:100}
ht
print(D1<=D2)
(a) True (b) False
(c) Cannot Compare the dictionaries (d) Error
w
(a) It will create new dictionary as dict={“Che”:72,”Bio”:80}
I
and old dict will be deleted.
ra
pI
(b) It will throw an error as dictionary cannot be updated.
xR
(c) It will simply update the dictionary as
dict={“Phy”:94,”Che”:72,”Bio”:80, “Eng”:95}
_N
om
(d) It will not throw any error but it will not do any changes
cw
in dict.
.c
W
18. Consider the coding given below and fill in the blanks:
se
fe
Dict_d={„BookName‟:‟Python‟,‟Author‟:”Arundhati Roy”}
cb
R
Dict_d.pop() # Statement 1
n4
List_L=[“java”,”SQL”,”Python”] 6p
ho
s-
List_L.pop() # Statement 2
st
yt
List_L________(True/False).
ne
e
its object
w
ha
/c
w
d={'a':'Delhi','b':'Mumbai','c':'Kolkata'}
m
for i in d:
co
if i in d[i]:
e.
x=len(d[i])
ub
print(x)
ut
D1.update(D2)
://
print (D1)
s
tp
w
(d) del(Dict1.[„Dictionary‟])
I
ra
2 MARKS / 3 -MARKS
pI
1. Write a statement in Python to declare a dictionary whose
xR
keys are Sub1, Sub2, Sub3 and values are Physics,
_N
Chemistry, Math respectively.
om
2. Debug the following code and underline the correction
cw
.c
made:
W
se
d=dict{ }
fe
cb
n=input("enter number of terms")
R
for i in range(n):
n4
a=input("enter a character") 6p
ho
s-
d[i]=a
st
yt
l/U
>>>print(squares.pop(4))
ne
e
.L
ha
Emp["HAPPY"] = 23000
/c
w
Emp["SMITH"] = 14000
co
print( Emp.values())
e.
d1={"a":10,"b":2,"c":3}
str1=""
o ut
for i in d1:
.y
str1=str1+str(d1[i])+" "
w
str2=str1[ : -1]
w
w
print(str2[: : -1])
://
d={"Rohan":67,"Ahasham":78,"naman":89,"pranav":79}
tp
print(d)
ht
sum=0
for i in d:
sum+=d[i]
print(sum)
print("sum of values of dictionaries",sum)
w
Mydict[(4,5,6)]=20
I
ra
Mydict[(1,2)]=25
pI
total=0
xR
for i in Mydict:
_N
total=total+Mydict[i]
om
print(total)
cw
.c
print(Mydict)
W
se
9. Write the output of the code given below:
fe
cb
d1 = {"name": "Aman", "age": 26}
R
d2 = {27:'age','age':28}
n4
d1.update(d2) 6p
ho
s-
print(d1.values())
st
yt
l/U
ne
newMarks = {'Suchitra':66,'Arun':55,'Prkash':49}
e
.L
Marks.update(newMarks)
w
ha
/c
w
if(value<55):
co
e.
print()
ut
my_dict = { }
.y
my_dict[(1,2,4)] = 8
w
w
my_dict[(4,2,1)] = 10
w
my_dict[(1,2)] = 12
://
sum = 0
s
tp
for k in my_dict:
ht
sum += my_dict[k]
print (sum)
print(my_dict)
w
L=[10,20,30]
I
ra
D={ }
pI
N=len(S)
xR
for i in range(N):
_N
D[L[i]]=S[i]
om
for K,V in D.items():
cw
.c
print(K,V,sep="*",end=",")
W
se
14. What will be the output, given by the following piece
fe
cb
of code:
R
D1= {"A":12, "B": 6, "C" : 50, "D" : 70}
n4
s-
15. Predict the output of the following:
st
yt
P=1400
C
np
l/U
D={'KTM':45,'RoyalEnfield':75,'Jawa':33,'TVS':89,
ar
'Yamaha':111}
ne
e
for j in D:
.L
n
w
ha
if(len(j)>5):
w
P=P-D[j]
/c
w
print(j)
co
X={'Suzuki':1000,'Bajaja':21}
D.update(X)
e.
ub
print(X)
print(D)
ut
print(D.get('Jawa','KTM'))
o
.y
w
w
w
*****************************************************
://
s
tp
ht