gs gs109 Python Tuples - Python Tuples - Quiz No.3
gs gs109 Python Quiz
This quiz belongs to book/course code gs gs109 Python of gs organization. We have 134 quizzes available related to the book/course Python. This quiz has a total of 10 multiple choice questions (MCQs) to prepare and belongs to topic Python Tuples. NVAEducation wants its users to help them learn in an easy way. For that purpose, you are free to prepare online MCQs and quizzes.
NVAEducation also facilitates users to contribute in online competitions with other students to make a challenging situation to learn in a creative way. You can create one to one, and group competition on an topic of a book/course code. Also on NVAEducation you can get certifications by passing the online quiz test.
Question 1: Is the following Python code valid?
>>> a,b,c=1,2,3 >>> a,b,c
Yes, [1,2,3] is printed
No, invalid syntax
Yes, (1,2,3) is printed
1 is printed
Question 2: What will be the output of the following Python code?
a = ('check',) n = 2 for i in range(int(n)): a = (a,) print(a)
Error, tuples are immutable
(('check',),) ((('check',),),)
((‘check’,)’check’,)
(('check',)’check’,) ((('check',)’check’,)’check’,)
Question 3: Is the following Python code valid?
>>> a,b=1,2,3
Yes, this is an example of tuple unpacking. a=1 and b=2
Yes, this is an example of tuple unpacking. a=(1,2) and b=3
No, too many values to unpack
Yes, this is an example of tuple unpacking. a=1 and b=(2,3)
Question 4: What will be the output of the following Python code?
>>> a=(1,2) >>> b=(3,4) >>> c=a+b >>> c
(4,6)
(1,2,3,4)
Error as tuples are immutable
None
Question 5: What will be the output of the following Python code?
>>> a,b=6,7 >>> a,b=b,a >>> a,b
(6,7)
Invalid syntax
(7,6)
Nothing is printed
Question 6: What will be the output of the following Python code?
>>> import collections >>> a=collections.namedtuple('a',['i','j']) >>> obj=a(i=4,j=7) >>> obj
a(i=4, j=7)
obj(i=4, j=7)
(4,7)
An exception is thrown
Question 8: Is the following Python code valid?
>>> a=2,3,4,5 >>> a
Yes, 2 is printed
Yes, [2,3,4,5] is printed
No, too many values to unpack
Yes, (2,3,4,5) is printed
Question 9: What will be the output of the following Python code?
>>> a=(2,3,1,5) >>> a.sort() >>> a
(1,2,3,5)
(2,3,1,5)
None
Error, tuple has no attribute sort
Question 10: Is the following Python code valid?
>>> a=(1,2,3) >>> b=a.update(4,)
Yes, a=(1,2,3,4) and b=(1,2,3,4)
Yes, a=(1,2,3) and b=(1,2,3,4)
No because tuples are immutable
No because wrong syntax for update() method