TechBeamersTechBeamers
  • Learn ProgrammingLearn Programming
    • Python Programming
      • Python Basic
      • Python OOP
      • Python Pandas
      • Python PIP
      • Python Advanced
      • Python Selenium
    • Python Examples
    • Selenium Tutorials
      • Selenium with Java
      • Selenium with Python
    • Software Testing Tutorials
    • Java Programming
      • Java Basic
      • Java Flow Control
      • Java OOP
    • C Programming
    • Linux Commands
    • MySQL Commands
    • Agile in Software
    • AngularJS Guides
    • Android Tutorials
  • Interview PrepInterview Prep
    • SQL Interview Questions
    • Testing Interview Q&A
    • Python Interview Q&A
    • Selenium Interview Q&A
    • C Sharp Interview Q&A
    • PHP Interview Questions
    • Java Interview Questions
    • Web Development Q&A
  • Self AssessmentSelf Assessment
    • Python Test
    • Java Online Test
    • Selenium Quiz
    • Testing Quiz
    • HTML CSS Quiz
    • Shell Script Test
    • C/C++ Coding Test
Search
  • Python Multiline String
  • Python Multiline Comment
  • Python Iterate String
  • Python Dictionary
  • Python Lists
  • Python List Contains
  • Page Object Model
  • TestNG Annotations
  • Python Function Quiz
  • Python String Quiz
  • Python OOP Test
  • Java Spring Test
  • Java Collection Quiz
  • JavaScript Skill Test
  • Selenium Skill Test
  • Selenium Python Quiz
  • Shell Scripting Test
  • Latest Python Q&A
  • CSharp Coding Q&A
  • SQL Query Question
  • Top Selenium Q&A
  • Top QA Questions
  • Latest Testing Q&A
  • REST API Questions
  • Linux Interview Q&A
  • Shell Script Questions
© 2024 TechBeamers. All Rights Reserved.
Reading: 30 Python Programming Questions On List, Tuple, and Dictionary
Font ResizerAa
TechBeamersTechBeamers
Font ResizerAa
  • Python
  • SQL
  • C
  • Java
  • Testing
  • Selenium
  • Agile Concepts Simplified
  • Linux
  • MySQL
  • Python Quizzes
  • Java Quiz
  • Testing Quiz
  • Shell Script Quiz
  • WebDev Interview
  • Python Basic
  • Python Examples
  • Python Advanced
  • Python OOP
  • Python Selenium
  • General Tech
Search
  • Programming Tutorials
    • Python Tutorial
    • Python Examples
    • Java Tutorial
    • C Tutorial
    • MySQL Tutorial
    • Selenium Tutorial
    • Testing Tutorial
  • Top Interview Q&A
    • SQL Interview
    • Web Dev Interview
  • Best Coding Quiz
    • Python Quizzes
    • Java Quiz
    • Testing Quiz
    • ShellScript Quiz
Follow US
© 2024 TechBeamers. All Rights Reserved.
Python BasicPython Tutorials

30 Python Programming Questions On List, Tuple, and Dictionary

Last updated: Apr 23, 2024 2:01 pm
By Meenakshi Agarwal
Share
15 Min Read
30 Quick Python Programming Questions On List, Tuple & Dictionary
SHARE

Ready to boost your Python skills? We’ve brought you the 30 most critical Python programming questions on List, Tuple, and Dictionary – the foundation of every Python application. Gain a deep understanding of these data types and take your coding to the next level.

Python Programming Q & A – List, Tuple, and Dictionary

By the end of this tutorial, confidently use List, Tuple, and Dictionary data types to supercharge your Python projects. Let’s dive in and unlock your Python potential!

We hope you are ready to start this 30-question questionnaire. However, we have also curated the best 100 Python interview questions on various Python programming topics. Please save this list of 100 questions and check it out after you finish the 30 questions on List, Tuple, and Dictionary.

10 Objective questions and answers on the list

Here is a short definition of a list in Python to help you understand it quickly.

  • A list, in Python, stores a sequence of objects in a defined order. Python lists allow indexing and iterating through its elements. Lists are mutable objects that you can modify after creation.

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

a=[1,2,3,4,5,6,7,8,9]
print(a[::2])
  • A. [1,2]
  • B. [8,9]
  • C. [1,3,5,7,9]
  • D. [1,2,3]
Hover here to view the answer!
Answer. C

Q-2. The code below manipulates a Python list using the slicing operator. What will be the output?

a=[1,2,3,4,5,6,7,8,9]
a[::2]=10,20,30,40,50,60
print(a)
  • A. ValueError: Attempt to assign a sequence of size 6 to an 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]
Hover here to view the answer!
Answer. A

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

a=[1,2,3,4,5]
print(a[3:0:-1])
  • A. Syntax error
  • B. [4, 3, 2]
  • C. [4, 3]
  • D. [4, 3, 2, 1]
Hover here to view the answer!
Answer. B

Q-4. What will the Python function in the below code do? Choose the right option.

def f(value, values):
    v = 1
    values[0] = 44
t = 3
v = [1, 2, 3]
f(t, v)
print(t, v[0])
  • A. 1 44
  • B. 3 1
  • C. 3 44
  • D. 1 1
Hover here to view the answer!
Answer. C

Q-5. What is the correct command to shuffle the given Python list?

fruit=['apple', 'banana', 'papaya', 'cherry']
  • A. fruit.shuffle()
  • B. shuffle(fruit)
  • C. random.shuffle(fruit)
  • D. random.shuffleList(fruit)
Hover here to view the answer!
Answer. C

Q-6. The function below is iterating over a nested Python list. What will it return?

data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
def fun(m):
    v = m[0][0]

    for row in m:
        for element in row:
            if v < element: v = element

    return v
print(fun(data[0]))
  • A. 1
  • B. 2
  • C. 3
  • D. 4
  • E. 5
  • F. 6
Hover here to view the answer!
Answer. D

Q-7. The below code is iterating over a nested Python list. What will be the output?

arr = [[1, 2, 3, 4],
       [4, 5, 6, 7],
       [8, 9, 10, 11],
       [12, 13, 14, 15]]
for i in range(0, 4):
    print(arr[i].pop())
  • A. 1 2 3 4
  • B. 1 4 8 12
  • C. 4 7 11 15
  • D. 12,13,14,15
Hover here to view the answer!
Answer. C

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

def f(i, values = []):
    values.append(i)
    print (values)
    return values
f(1)
f(2)
f(3)
  • A. [1] [2] [3]
  • B. [1, 2, 3]
  • C. [1] [1, 2] [1, 2, 3]
  • D. 1 2 3
Hover here to view the answer!
Answer. C

Q-9. The below code is using a Python list and iterates using the range() function. What will be the output?

arr = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
    arr[i - 1] = arr[i]
for i in range(0, 6): 
    print(arr[i], end = " ")
  • 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
Hover here to view the answer!
Answer. D

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

fruit_list1 = ['Apple', 'Berry', 'Cherry', 'Papaya']
fruit_list2 = fruit_list1
fruit_list3 = fruit_list1[:]

fruit_list2[0] = 'Guava'
fruit_list3[1] = 'Kiwi'

sum = 0
for ls in (fruit_list1, fruit_list2, fruit_list3):
    if ls[0] == 'Guava':
        sum += 1
    if ls[1] == 'Kiwi':
        sum += 20

print (sum)
  • A. 22
  • B. 21
  • C. 0
  • D. 43
Hover here to view the answer!
Answer. A

Do you know how can you traverse multiple lists in parallel? Learn Python zip function to iterate lists in parallel.

Out of the 30 questions on List, Tuple, and Dictionary, you have completed the 10 questions on the list. Now, check out the 10 Python programming exercises/questions on tuples and 10 on the Python dictionary.

Let’s take up 10 questions on Python tuples!

Before you dive in to solve the below questions, have a bird-view on the concept of a tuple in Python.

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

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

init_tuple = ()
print (init_tuple.__len__())
  • A. None
  • B.  1
  • C. 0
  • D. Exception
Hover here to view the answer!
Answer. C

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

init_tuple_a = 'a', 'b'
init_tuple_b = ('a', 'b')

print (init_tuple_a == init_tuple_b)
  • A. 0
  • B.  1
  • C. False
  • D. True
Hover here to view the answer!
Answer. D

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

init_tuple_a = '1', '2'
init_tuple_b = ('3', '4')

print (init_tuple_a + init_tuple_b)
  • A. (1, 2, 3, 4)
  • B.  (‘1’, ‘2’, ‘3’, ‘4’)
  • C. [‘1’, ‘2’, ‘3’, ‘4’]
  • D. None
Hover here to view the answer!
Answer. B

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

init_tuple_a = 1, 2
init_tuple_b = (3, 4)

[print(sum(x)) for x in [init_tuple_a + init_tuple_b]]
  • A. Nothing gets printed.
  • B.  4
  • C. 10
  • D. TypeError: unsupported operand type
Hover here to view the answer!
Answer. C

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

init_tuple = [(0, 1), (1, 2), (2, 3)]

result = sum(n for _, n in init_tuple)

print(result)
  • A. 3
  • B. 6
  • C. 9
  • D. Nothing gets printed.
Hover here to view the answer!
Answer. B

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

  • A. Tuples have structure, and lists have an order.
  • B. Tuples are homogeneous, and lists are heterogeneous.
  • C. Tuples are immutable, and lists are mutable.
  • D. All of them.
Hover here to view the answer!
Answer. A and C

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

l = [1, 2, 3]

init_tuple = ('Python',) * (l.__len__() - l[::-1][0])

print(init_tuple)
  • A. ()
  • B. (‘Python’)
  • C. (‘Python’, ‘Python’)
  • D. Runtime Exception.
Hover here to view the answer!
Answer. A

Q-8. What will be the output of the following code using a Python tuple?

init_tuple = ('Python') * 3

print(type(init_tuple))
  • A. <class ‘tuple’>
  • B. <class ‘str’>
  • C. <class ‘list’>
  • D. <class ‘function’>
Hover here to view the answer!
Answer. B

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

init_tuple = (1,) * 3

init_tuple[0] = 2

print(init_tuple)
  • A. (1, 1, 1)
  • B. (2, 2, 2)
  • C. (2, 1, 1)
  • D. TypeError: ‘tuple’ object does not support item assignment
Hover here to view the answer!
Answer. D

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

init_tuple = ((1, 2),) * 7

print(len(init_tuple[3:8]))
  • A. Exception
  • B. 5
  • C. 4
  • D. None
Hover here to view the answer!
Answer. C

Finally, here are the 10 Python programming questions on the dictionary data type.

Let’s not miss 10 more questions on dictionaries.

Here is a short description of a dictionary in Python to let you understand it quickly.

  • 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.

Q-1. What is the output of the below Python code?

a = {(1,2):1,(2,3):2}
print(a[1,2])
  • A. Key Error
  • B.  1
  • C. {(2,3):2}
  • D. {(1,2):1}
Hover here to view the answer!
Answer. B

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

a = {'a':1,'b':2,'c':3}
print (a['a','b'])
  • A. Key Error
  • B. [1,2]
  • C. {‘a’:1,’b’:2}
  • D. (1,2)
Hover here to view the answer!
Answer. A

Q-3. The code below has a Python function writing to a dictionary. What will it print in the end?

fruit = {}

def addone(index):
    if index in fruit:
        fruit[index] += 1
    else:
        fruit[index] = 1
        
addone('Apple')
addone('Banana')
addone('apple')
print (len(fruit))
  • A. 1
  • B. 2
  • C. 3
  • D. 4
Hover here to view the answer!
Answer. C

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

arr = {}
arr[1] = 1
arr['1'] = 2
arr[1] += 1

sum = 0
for k in arr:
    sum += arr[k]

print (sum)
  • A. 1
  • B. 2
  • C. 3
  • D. 4
Hover here to view the answer!
Answer. D

Q-5. How will the Python dictionary in the below code behave? Choose the right answer.

my_dict = {}
my_dict[1] = 1
my_dict['1'] = 2
my_dict[1.0] = 4

sum = 0
for k in my_dict:
    sum += my_dict[k]
    
print (sum)
  • A. 7
  • B. Syntax error
  • C. 3
  • D. 6
Hover here to view the answer!
Answer. D

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

my_dict = {}
my_dict[(1,2,4)] = 8
my_dict[(4,2,1)] = 10
my_dict[(1,2)] = 12

sum = 0
for k in my_dict:
    sum += my_dict[k]

print (sum)
print(my_dict)
  • 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}
Hover here to view the answer!
Answer. B

Q-7. What will the following Python dictionary code print in its result?

box = {}
jars = {}
crates = {}
box['biscuit'] = 1
box['cake'] = 3
jars['jam'] = 4
crates['box'] = box
crates['jars'] = jars
print (len(crates[box]))
  • A. 1
  • B. 3
  • C. 4
  • D. Type Error
Hover here to view the answer!
Answer. D

Q-8. What will be the output of the Python code given below?

dict = {'c': 97, 'a': 96, 'b': 98}

for _ in sorted(dict):
    print (dict[_])
  • A. 96 98 97
  • B. 96 97 98
  • C. 98 97 96
  • D. NameError
Hover here to view the answer!
Answer. A

Q-9. Will the ID of a copied Python dictionary object change? Check your answer.

rec = {"Name" : "Python", "Age":"20"}
r = rec.copy()
print(id(r) == id(rec))
  • A. True
  • B. False
  • C. 0
  • D. 1
Hover here to view the answer!
Answer. B

Q-10. What will be the result of the below Python code?

rec = {"Name" : "Python Programmer", "Age":"20", "Addr" : "NJ", "Country" : "USA"}
id1 = id(rec)
del rec
rec = {"Name" : "Python Programmer", "Age":"20", "Addr" : "NJ", "Country" : "USA"}
id2 = id(rec)
print(id1 == id2)
  • A. True
  • B. False
  • C. 1
  • D. Exception
Hover here to view the answer!
Answer. A

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

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

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

Best,

TechBeamers.

You Might Also Like

How to Connect to PostgreSQL in Python

Generate Random IP Address (IPv4/IPv6) in Python

Python Remove Elements from a List

Selenium Python Extent Report Guide

10 Python Tricky Coding Exercises

TAGGED:Interactive Python Quiz
Meenakshi Agarwal Avatar
By Meenakshi Agarwal
Follow:
Hi, I'm Meenakshi Agarwal. I have a Bachelor's degree in Computer Science and a Master's degree in Computer Applications. After spending over a decade in large MNCs, I gained extensive experience in programming, coding, software development, testing, and automation. Now, I share my knowledge through tutorials, quizzes, and interview questions on Python, Java, Selenium, SQL, and C# on my blog, TechBeamers.com.
Previous Article Create a Selenium Test Suite in Python Unittest Build A Selenium Python Test Suite using Unittest
Next Article Python File Handling Quiz Part-1 for Beginners Python File Handling Quiz Part-1

Popular Tutorials

SQL Interview Questions List
50 SQL Practice Questions for Good Results in Interview
SQL Interview Nov 01, 2016
Demo Websites You Need to Practice Selenium
7 Sites to Practice Selenium for Free in 2024
Selenium Tutorial Feb 08, 2016
SQL Exercises with Sample Table and Demo Data
SQL Exercises – Complex Queries
SQL Interview May 10, 2020
Java Coding Questions for Software Testers
15 Java Coding Questions for Testers
Selenium Tutorial Jun 17, 2016
30 Quick Python Programming Questions On List, Tuple & Dictionary
30 Python Programming Questions On List, Tuple, and Dictionary
Python Basic Python Tutorials Oct 07, 2016
//
Our tutorials are written by real people who’ve put in the time to research and test thoroughly. Whether you’re a beginner or a pro, our tutorials will guide you through everything you need to learn a programming language.

Top Coding Tips

  • PYTHON TIPS
  • PANDAS TIPSNew
  • DATA ANALYSIS TIPS
  • SELENIUM TIPS
  • C CODING TIPS
  • GDB DEBUG TIPS
  • SQL TIPS & TRICKS

Top Tutorials

  • PYTHON TUTORIAL FOR BEGINNERS
  • SELENIUM WEBDRIVER TUTORIAL
  • SELENIUM PYTHON TUTORIAL
  • SELENIUM DEMO WEBSITESHot
  • TESTNG TUTORIALS FOR BEGINNERS
  • PYTHON MULTITHREADING TUTORIAL
  • JAVA MULTITHREADING TUTORIAL

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Loading
TechBeamersTechBeamers
Follow US
© 2024 TechBeamers. All Rights Reserved.
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
  • Terms of Use
TechBeamers Newsletter - Subscribe for Latest Updates
Join Us!

Subscribe to our newsletter and never miss the latest tech tutorials, quizzes, and tips.

Loading
Zero spam, Unsubscribe at any time.
x