0% found this document useful (0 votes)
75 views2 pages

Swayam Assessment 7

srt

Uploaded by

shubham jha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views2 pages

Swayam Assessment 7

srt

Uploaded by

shubham jha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Swayam

Assessment-7

1) What will be the output of the following code?


pythonCopy code

x=(1,6,7) print(2*x)
Options: a) (2,12,14) b) (1,1,6,6,7,7) c) (1, 6, 7, 1, 6, 7) d) Error
Correct answer: c) (1, 6, 7, 1, 6, 7)

2) Which of the following is correct about a tuple?

Options: a) A tuple can be modified after it is created. b) A tuple cannot contain mixed types of
data. c) Elements in a tuple can be accessed using their index. d) Tuples are faster to iterate
through than lists because they are mutable.
Correct answer: c) Elements in a tuple can be accessed using their index.

3) How do you delete a tuple in Python?


Options: a) Using the del keyword: del tuple_name b) Using the remove() method:
tuple_name.remove() c) Tuples cannot be deleted. d) Using the pop() method:
tuple_name.pop()
Correct answer: c) Tuples cannot be deleted.

4) What will be the output of the following code?


pythonCopy code
z=("amar","akbar","anthony") print(z[-1:0])
Options: a) ("amar") b) ("akbar") c) ("anthony") d) ()
Correct answer: d) ()

5) Which of the following is a Python tuple?


Options: a) {5,6,7} b) [5,6,7] c) (5,6,7) d) <5,6,7>
Correct answer: c) (5,6,7)
6) Which of the following is the correct way to create a tuple with a single element?

Options: a) my_tuple = (1) b) my_tuple = 1, c) my_tuple = (1,) d) my_tuple = {1}


Correct answer: c) my_tuple = (1,)

7) Which of the following operations is not supported by tuples in Python?


Options: a) Concatenation b) Repetition c) Modification d) Slicing
Correct answer: c) Modification

8) What will be the output of the following code?


pythonCopy code
x1 = (1, 5, 4, 6) x2 = (1, 2, 3, 4) print(x1 < x2)
Options: a) False b) True

Correct answer: a) False

9) How do you swap the values of two variables a and b in Python using tuple unpacking?

Options: a) a, b = (b, a) b) a = b; b = a c) (a, b) = b, a d) ab=ba


Correct answer: a) a, b = (b, a)

10) What will be the output of the following code?


pythonCopy code
def my(): return (1, 2), (3, 4) a, b = my() print(a) print(b)

Options: a) 1 2 on one line and 3 4 on the next line.


b) (1, 2) on one line and (3, 4) on the next line. c) ((1, 2), (3, 4)) d) Error
Correct answer: b) (1, 2) on one line and (3, 4) on the next line

You might also like