My Report

Python Tuples Test – 1


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. 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)

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

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

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

numberGames = {}
numberGames[(1,2,4)] = 8
numberGames[(4,2,1)] = 10
numberGames[(1,2)] = 12
sum = 0
for k in numberGames:
    sum += numberGames[k]
print len(numberGames) + sum

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

>>>t = (1, 2)
>>>2 * t

5. Which of the following is a Python tuple?

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

>>>t=(1,2,4,3)
>>>t[1:3]

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

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

>>>t=(1,2,4,3)
>>>t[1:-1]

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

>>>t = (1, 2, 4, 3, 8, 9)
>>>[t[i] for i in range(0, len(t), 2)]

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

>>>t1 = (1, 2, 4, 3)
>>>t2 = (1, 2, 3, 4)
>>>t1 < t2

 

Start practicing “1000 MCQs on Python”, and once you are ready, you can take tests on all topics by attempting our “Python Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.