Advertisement

Python Quiz - TUPLES


 1.    A Python tuple can also be created without using parentheses


A.    False

B.    True


Ans :    True                         



2.     Suppose t = (1, 2, 4, 3), which of the following is incorrect?


A.    print(t[3])

B.    t[3] = 45

C.    print(max(t))

D.    print(len(t))


Ans :    t[3] = 45                          


3.    Choose the correct option with respect to Python.


A.    Both tuples and lists are immutable.

B.    Tuples are immutable while lists are mutable.

C.    Both tuples and lists are mutable.

D.    Tuples are mutable while lists are immutable.


Ans : Tuples are immutable while lists are mutable.          


4.    Which of the following options will not result in an error when performed on tuples in Python where tupl=(5,2,7,0,3)?


A.    tupl[1]=2

B.    tupl.append(2)

C.    tupl1=tupl+tupl

D.    tupl.sort()


Ans :    tupl1=tupl+tupl                      


5.    What is the output of the following tuple operation

aTuple = (100, 200, 300, 400, 500)     

aTuple.pop(2)                                      

print(aTuple)                                       


A.    (100, 200, 400, 500)

B.    (100, 300, 400, 500)

C.    AttributeError


Ans :    AttributeError                     


6.    Choose the correct way to access value 20 from the following tuple

aTuple = ("Orange", [10, 20, 30], (5, 15, 25))     

A.    aTuple[1:2][1]

B.    aTuple[1:2](1)

C.    aTuple[1:2][1]

D.    aTuple[1][1]


Ans :    aTuple[1][1]                      


7.    What will be the output of the following Python code?

d = {"john":40, "peter":45}              

d["john"]                                             


A.    40

B.    45

C.    “john”

D.    “peter”


Ans :    40                            


8.    Which of the following creates a tuple?


A.    tuple1=("a","b")

B.    tuple1[2]=("a","b")

C.    tuple1=(5)*2

D.    None of the above


Ans :     tuple1=("a","b")                    


9.    What will be the output of below Python code?

tupl=("annie","hena","sid")

print(tupl[-3:0])                             


A.    ("annie")

B.    ()

C.    None

D.    Error as slicing is not possible in tuple.    

 

Ans :    ()                                       

 

10.   What will be the output of the following Python code?

>>>my_tuple = (1, 2, 3, 4)               

>>>my_tuple.append( (5, 6, 7) )     

>>>print len(my_tuple)                   


A.    1

B.    2

C.    5

D.    Error


Ans :    Error                      


11.   Which of the following is a Python tuple? 


A.    [1, 2, 3]

B.    (1, 2, 3)

C.    {1, 2, 3}

D.    {}


Ans :    (1,2,3)                         

12.   What will be the output of below Python code?

tupl=()                       

tupl1=tupl*2             

print(len(tupl1))       


A.    0

B.    2

C.    1

D.    Error as tuple object has no attribute to len


Ans :    0                                 


13.   What type of data is: a=[(1,1),(2,4),(3,9)]?


A.    Array of tuples

B.    List of tuples

C.    Tuples of lists

D.    Invalid type


Ans :    List of tuples                       


14.   What is the data type of (1)?


A.    Tuple

B.    Integer

C.    List

D.    Both tuple and integer


Ans :    Integer                      


15.   Tuples can’t be made keys of a dictionary.


A.    True

B.    False


Ans :    False                         


16.   If a=(1,2,3,4), a[1:-1] is _________


A.    Error, tuple slicing doesn’t exist

B.    [2,3]

C.    (2,3,4)

D.    (2,3)


Ans :    (2, 3)                          


17.   What will be the output of the following Python code?

>>> a,b=6,7           

>>> a,b=b,a           

>>> a,b                   


A.    (6,7)

B.    Invalid syntax

C.    (7,6)

D.    Nothing is printed


Ans :    (7, 6)                          


18.   What will be the output of the following Python code?

>>> a=(2,3,1,5)              

>>> a.sort()                    

>>> a                              


A.    (1,2,3,5)

B.    (2,3,1,5)

C.    None

D.    Error, tuple has no attribute sort


Ans :    Error, tuple has no attribute sort              


19.   Is the following Python code valid?

>>> a,b,c=1,2,3       

>>> a,b,c                 


A.    Yes, [1,2,3] is printed

B.    No, invalid syntax

C.    Yes, (1,2,3) is printed

D.    1 is printed


Ans :    Yes, (1,2,3) is printed             


20.   What will be the output of the following Python code?

>>> a=(2,3,4)         

>>> sum(a,3)          


A.    Too many arguments for sum() method

B.    The method sum() doesn’t exist for tuples

C.    12

D.    9


Ans :    12                      

Post a Comment

0 Comments