Python Coding Questions – List, Tuple and Dictionary

In Python, the most important data structures are List, Tuple, and Dictionary. So you should know how they work and when to use them. That’s why we brought these 25 Python programming questions on List, Tuple, and Dictionary in this blog post.

Also, with the help of these constructs, you can create robust and scalable Python applications. But it’ll require a thorough understanding of these features and their usage.

So before we go through the list of Python programming questions, it is essential to understand the difference between the triad.

But if you’re a serious learner, then you might also want to go through the following posts.

In next few lines, we’ll draw a comparison which will help you choose the best option depending on the situation.

A list, in Python, stores a sequence of objects in a defined order. They allow indexing or iterating through the list. Next, lists are mutable which you can modify after creation.

A tuple is though similar to a list, but it’s immutable. Another semantic difference between a list and a tuple is “Tuples are heterogeneous data structures whereas the list is a homogeneous sequence.“.

A dictionary is an associative array of key-value pairs. It’s unordered and requires the keys to be hashable. Search operations happen to be faster in a dictionary as they use keys for lookups.

Now, read the below questions and answer them carefully.

25 Python programming questions on List, Tuple, and Dictionary.

Q-1. What will be the output of the following code snippet?

A. Key Error
B.  1
C. {(2,3):2}
D. {(1,2):1}

Click here to view the answer.
Answer. B

 

Q-2. What will be the output of the following code snippet?

A. Key Error
B. [1,2]
C. {‘a’:1,’b’:2}
D. (1,2)

Click here to view the answer.
Answer. A

 

Q-3. What will be the output of the following code snippet?

A. [1,2]
B. [8,9]
C. [1,3,5,7,9]
D. [1,2,3]

Click here to view the answer.
Answer. C

 

Q-4. What will be the output of the following code snippet?

A. ValueError: attempt to assign sequence of size 6 to extended slice of size 5
B. [10, 2, 20, 4, 30, 6, 40, 8, 50, 60]
C. [1, 2, 10, 20, 30, 40, 50, 60]
D. [1, 10, 3, 20, 5, 30, 7, 40, 9, 50, 60]

Click here to view the answer.
Answer. A

 

Q-5. What will be the output of the following code snippet?

A. Syntax error
B. [4, 3, 2]
C. [4, 3]
D. [4, 3, 2, 1]

Click here to view the answer.
Answer. B

 

Q-6. What will be the output of the following code snippet?

A. 1 44
B. 3 1
C. 3 44
D. 1 1

Click here to view the answer.
Answer. C

 

Q-7. What is the correct command to shuffle the following list?

A. fruit.shuffle()
B. shuffle(fruit)
C. random.shuffle(fruit)
D. random.shuffleList(fruit)

Click here to view the answer.
Answer. C

 

Q-8. What will be the output of the following code snippet?

A. 1
B. 2
C. 3
D. 4
E. 5
F. 6

Click here to view the answer.
Answer. D

 

Q-9. What will be the output of the following code snippet?

A. 1 2 3 4
B. 1 4 8 12
C. 4 7 11 15
D. 12,13,14,15

Click here to view the answer.
Answer. C

 

Q-10. What will be the output of the following code snippet?

A. [1] [2] [3]
B. [1, 2, 3]
C. [1] [1, 2] [1, 2, 3]
D. 1 2 3

Click here to view the answer.
Answer. C

 

Q-11. What will be the output of the following code snippet?

A. 1 2 3 4 5 6
B. 2 3 4 5 6 1
C. 1 1 2 3 4 5
D. 2 3 4 5 6 6

Click here to view the answer.
Answer. D

 

Q-12. What will be the output of the following code snippet?

A. 1
B. 2
C. 3
D. 4

 

Q-13. What will be the output of the following code snippet?

A. 1
B. 2
C. 3
D. 4

Click here to view the answer.
Answer. D

 

Q-14. What will be the output of the following code snippet?

A. 7
B. Syntax error
C. 3
D. 6

Click here to view the answer.
Answer. D

 

Q-15. What will be the output of the following code snippet?

A. Syntax error
B. 30  
    {(1, 2): 12, (4, 2, 1): 10, (1, 2, 4): 8}
C. 47
    {(1, 2): 12, (4, 2, 1): 10, (1, 2, 4): 8}
D. 30
    {[1, 2]: 12, [4, 2, 1]: 10, [1, 2, 4]: 8}

Click here to view the answer.
Answer. B

 

Q-16. What will be the output of the following code snippet?

A. 22
B. 21
C. 0
D. 43

Click here to view the answer.
Answer. A

 

Q-17. What will be the output of the following code snippet?

A. correct
B. incorrect
C. Throws an exception
D. None

Click here to view the answer.
Answer. B

 

Q-18. What will be the output of the following code snippet?

A. s
B. w
C. W
D. winter
E. a

Click here to view the answer.
Answer. B

 

Q-19. What will be the output of the following code snippet?

A. 5
B. 7
C. AttributeError
D. 4

Click here to view the answer.
Answer. C

 

Q-20. What will be the output of the following code snippet?

A. 3 4 5 1
    33 6 1 2
B. 3 4 5 1 33 6 1 2
C. 1 3 4 5
D. 1 3 4 5
    1 2 6 33

Click here to view the answer.
Answer. D

 

Q-21. What will be the output of the following code snippet?

A. 5 33
B. 3 33
C. 5 6
D. 1 2

Click here to view the answer.
Answer. A

 

Q-22. What will be the output of the following code snippet?

A. 5
B. 8
C. 4
D. 6

Click here to view the answer.
Answer. A

 

Q-23. Which of the following function returns a random item from a list, tuple, or string?

A. choice(seq)
B. randrange ([start,] stop [,step])
C. random()
D. seed([x])

Click here to view the answer.
Answer. A

 

Q-24. What will be the output of the following code snippet?

A. 1
B. 3
C. 4
D. Type Error

Click here to view the answer.
Answer. D

 

Q-25. What will be the output of the following code snippet?

A. [3, 4, 5]
B. [1, 2, 3]
C. [3, 4, 5] [1, 2, 3]
D. None

Click here to view the answer.
Answer. A

 

Summary – Python Programming Questions on List, Tuple, and Dictionary.

We tried to address some of the key Python programming constructs in this post with the help 25 leading questions. Hope, you would’ve enjoyed the post.

In the next post, we’ll bring an another interesting topic on Python programming. Till then, enjoy reading and keep learning.

Best,

TechBeamers.

Leave a Reply


*