30 Quick Python Programming Questions On List, Tuple & 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 30 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 post.

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.

Python Programming Questions.

30 Quick Python Programming Questions On List, Tuple & Dictionary

Quick Python Programming Questions.

Let’s begin with lists in Python.

Q-1. 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-2. 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-3. 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-4. 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-5. 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-6. 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-7. 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-8. 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-9. 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-10. 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

Let’s begin with tuples in Python.

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

A. None
B.  1
C. 0
D. Exception

Click here to view the answer.
Answer. C

 

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

A. 0
B.  1
C. False
D. True

Click here to view the answer.
Answer. D

 

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

A. (1, 2, 3, 4)
B.  (‘1’, ‘2’, ‘3’, ‘4’)
C. [‘1’, ‘2’, ‘3’, ‘4’]
D. None

Click here to view the answer.
Answer. B

 

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

A. Nothing gets printed.
B.  4
C. 10
D. TypeError: unsupported operand type

Click here to view the answer.
Answer. C

 

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

A. 3
B. 6
C. 9
D. Nothing gets printed.

Click here to view the answer.
Answer. B

 

Q-6. Which of the following statements given below is/are true?

A. Tuples have structure, lists have an order.
B. Tuples are homogeneous, lists are heterogeneous.
C. Tuples are immutable, lists are mutable.
D. All of them.

Click here to view the answer.
Answer. A & C

 

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

A. ()
B. (‘Python’)
C. (‘Python’, ‘Python’)
D. Runtime Exception.

Click here to view the answer.
Answer. A

 

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

A. <class ‘tuple’>
B. <class ‘str’>
C. <class ‘list’>
D. <class ‘function’>

Click here to view the answer.
Answer. B

 

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

A. (1, 1, 1)
B. (2, 2, 2)
C. (2, 1, 1)
D. TypeError: ‘tuple’ object does not support item assignment

Click here to view the answer.
Answer. D

 

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

A. Exception
B. 5
C. 4
D. None

Click here to view the answer.
Answer. C

Let’s begin with dictionaries in Python.

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
B. 2
C. 3
D. 4

Click here to view the answer.
Answer. C

 

Q-4. 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-5. 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-6. 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-7. 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-8. What will be the output of the following code snippet?

A. 96 98 97
B. 96 97 98
C. 98 97 96
D. NameError

Click here to view the answer.
Answer. A

 

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

A. True
B. False
C. 0
D. 1

Click here to view the answer.
Answer. B

 

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

A. True
B. False
C. 1
D. Exception

Click here to view the answer.
Answer. A

 

Summary – Python Programming Questions [List, Tuple, & Dictionary].

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

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

*