Is the following Python code valid?
>>> a=(1,2,3)
>>> b=a.update(4,)
a) Yes, a=(1,2,3,4) and b=(1,2,3,4)
b) Yes, a=(1,2,3) and b=(1,2,3,4)
c) No because tuples are immutable
d) No because wrong syntax for update() method
Answer: c
Explanation: Tuple doesn’t have any update() attribute because it is immutable.
Related Posts
What will be the output of the following Python code?
>>> a=[(2,4),(1,2),(3,9)]
>>> a.sort()
>>> aWhat will be the output of the following Python code?
>>> a=(2,3,1,5)
>>> a.sort()
>>> aIs the following Python code valid?
>>> a=2,3,4,5
>>> aTuples can’t be made keys of a dictionary.
What will be the output of the following Python code?
>>> import collections
>>> a=collections.namedtuple(‘a’,[‘i’,’j’])
>>> obj=a(i=4,j=7)
>>> objWhat will be the output of the following Python code?
>>> a,b=6,7
>>> a,b=b,a
>>> a,bWhat will be the output of the following Python code?
>>> a=(1,2)
>>> b=(3,4)
>>> c=a+b
>>> c
Join The Discussion