What will be the output of the following Python code?
a={1:5,2:3,3:4}a.pop(3) print(a)
{1: 5}
{1: 5, 2: 3}
Error, syntax error for pop() method
{1: 5, 3: 4}
3
5
25
1
What is the output of the following program:
print ("Hello World"[::-1])
dlroW olleH
Hello Worl
D
error
Concatenation
Membership
Slicing
All of the above
list1 = [11, 2, 23]list2 = [11, 2, 2]print(list1 < list2)
True
False
Error
None
d = {0: 'a', 1: 'b', 2: 'c'}for x in d.values(): print(x)
0 1 2
a b c
0 a 1 b 2 c
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
('abc’)
('a', 'b', 'c’)
['a', 'b', 'c’]
x | y
x ^ y
x & y
x – y
print("xyyzxyzxzxyy".count('xyy', 2, 11))
2
0
Built in
List
Tuple
Derived data
myList = [1, 5, 5, 5, 5, 1]max = myList[0]indexOfMax = 0for i in range(1, len(myList)): if myList[i] > max: max = myList[i] indexOfMax = i print(indexOfMax)
4
What will be the output of the following Python code snippet?
print('cd'.partition('cd'))
(‘cd’)
(”)
(‘cd’, ”, ”)
(”, ‘cd’, ”)
pop
remove
update
sum
19
18
17
tuple1=(5,1,7,6,2)tuple1.pop(2)print(tuple1)
(5,1,6,2)
(5,1,7,6)
(5,1,7,6,2)
dictionary()
set()
tuple()
list()
discard
dispose
Mutable data type
Allows duplicate values
Data type with unordered values
Immutable data type
What will be the output of the following?
print(sum(1,2,3))
6
print('xyyxyyxyxyxxy'.replace('xy', '12', 100))
xyyxyyxyxyxxy
12y12y1212x12
str1="helloworld"print(str1[::-1])
dlrowolleh
hello
world
helloworld
a= [1, 2, 3, 4, 5]for i in range(1, 5): a[i-1] = a[i]for i in range(0, 5): print(a[i],end = " ")
5 5 1 2 3
5 1 2 3 4
2 3 4 5 1
2 3 4 5 5
s={abs}
s={4, ‘abc’, (1,2)}
s={2, 2.2, 3, ‘xyz’}
s={san}
list1.add(5)
list1.append(5)
list1.addLast(5)
list1.addEnd(5)
insert()
append()
extend()
add()
d = {0, 1, 2}for x in d.values(): print(x)
None None None
count()
strip()
upper()
उपरोकà¥à¤¤ सà¤à¥€
[2, 6, 4]
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
{ }
[ ]
( )
More than one key can have the same value
The values of the dictionary can be accessed as dict[key]
Values of a dictionary must be unique
Values of a dictionary can be a mixture of letters and numbers
print('abcdefcdghcd'.split('cd', 0))
[‘abcdefcdghcd’]
‘abcdefcdghcd’
What is the output of the following code ?
ms = ('A','D', 'H','U','N','I','C')print(ms[1:4])
(‘D’, ‘H’, ‘U’)
(‘A’, ‘D’, ‘H’,’U’,’N’,’I’,’C’)
(‘D’,’H’,’U’,’N’,’I’,’C’)
What is the output of the following code:
L=['a','b','c','d']print ( "".join(L))
abcd
[‘a’,’b’,’c’,’d’]
keys, keys
key values, keys
keys, key values
key values, key values
['llo']
['hello']
['h', 'e', l', 'l', 'o']
None of the above
print(''.isdigit())
print s[0]
print s.lower()
s[1]='r'
print s.strip()
More than one key isn’t allowed
Keys must be immutable
Keys must be integers
When duplicate keys encountered, the last assignment wins
def f(values): values[0] = 44 v = [1, 2, 3]f(v)print(v)
[1, 44]
[1, 2, 3, 44]
[44, 2, 3]
[1, 2, 3]
print('Hello!2@#World'.istitle())
a = [0, 1, 2, 3]for a[0] in a: print(a[0])
0 1 2 3
0 1 2 2
3 3 3 3
test = {1:'A', 2:'B', 3:'C'}test = {} print(len(test))
An exception is thrown
print(list1[0])
print(list1[:2])
print(list1[:-2])
all of the mentioned
slicer
None of these-
Tuples have structure; lists have an order
Tuples are homogeneous, lists are heterogeneous.
Tuples are immutable, lists are mutable.
All of them
d = {0: 'a', 1: 'b', 2: 'c'}for i in d: print(i)
A collection of ordered and mutable data
A collection of unordered and mutable data with key-value pairs
A collection of immutable key-value pairs
A collection of values only
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