What will be the output of the following Python code snippet?
test = {1:'A', 2:'B', 3:'C'} test = {} print(len(test))
0
None
3
An exception is thrown
test = {1:'A', 2:'B', 3:'C'} del test[1] test[1] = 'D' del test[2] print(len(test))
2
Error as the key-value pair of 1:’A’ is already deleted
1
a = {} a[1] = 1 a['1'] = 2 a[1.0]=4 count = 0 for i in a: count += a[i] print(count) print(a)
6
a={} a['a']=1 a['b']=[2,3,4] print(a)
Exception is thrown
{‘b’: [2], ‘a’: 1}
{‘b’: [2], ‘a’: [3]}
{'a': 1, 'b': [2, 3, 4]}
What will be the output of the following Python code?
count={} count[(1,2,4)] = 5 count[(4,2,1)] = 7 count[(1,2)] = 6 count[(4,2,1)] = 2 tot = 0 for i in count: tot=tot+count[i] print(len(count)+tot)
25
17
16
Tuples can’t be made keys of a dictionary
a={} a[2]=1 a[1]=[2,3,4] print(a[1][1])
[2,3,4]
a={'B':5,'A':9,'C':7} print(sorted(a))
[‘A’,’B’,’C’]
[‘B’,’C’,’A’]
[5,7,9]
[9,5,7]
Returns True if any key of the dictionary is true
Returns False if dictionary is empty
Returns True if all keys of the dictionary are true
Method any() doesn’t exist for dictionary
a=dict() print(a[1])
An exception is thrown since the dictionary is empty
‘ ‘
Built in
List
Tuple
Derived data
getkeys()
key()
keys()
none of the mentioned
List is mutable & Tuple is immutable
List is immutable & Tuple is mutable
Both List and Tuple are Mutable
Both List and Tuple are Immutable
What data type is the object below ?
L=[1, 23, 'hello', 1]
Dictionary
Array
dlroWolleH
Hello Worl
d
Error
print s[0]
print s.lower()
s[1]='r'
print s.strip()
wd[4:]
wd[:4]
wd[-5:]
wd[:-4]
What is the output of the following code?
dict={"Joey":1, "Rachel":2} dict.update({"Phoebe":2}) print(dict)
{'Joey': 1, 'Rachel': 2, 'Phoebe': 2}
{“Joey”:1,”Rachel”:}
{“Joey”:1,”Phoebe”:2}
delete all the trailing whitespace characters
delete all the leading whitespace characters
delete all the leading and trailing whitespace characters
delete upper case characters
a = set('dcma') b = set('mlpc') print(a^b)
{‘d’, ‘c’, ‘m’, ‘l’, ‘p’, ‘c’}
{‘m’, ‘l’, ‘p’, ‘c’}
{‘d’, ‘c’, ‘m’, ‘a’}
None of These