Unit 2: Python data structures - Subjective Questions

ECAP776 • Practice Questions with Detailed Answers

20 questions

1

Define a Python string. Explain string indexing and slicing with suitable examples.

2

Explain commonly used Python string methods and demonstrate any five of them.

3

Describe different techniques for formatting strings in Python. Compare f-strings, str.format(), and the % operator.

4

Write and explain a Python program that determines whether a given string is a palindrome after ignoring spaces, punctuation, and letter case.

5

Define a Python list. Explain list creation, indexing, slicing, and mutability with examples.

6

Explain the differences among append(), extend(), insert(), remove(), pop(), and del when working with lists.

7

What is list comprehension? Explain its syntax and use it to create filtered and transformed lists.

8

Discuss shallow copying and deep copying of nested Python lists. Why can ordinary list copying produce unexpected results?

9

Define a set in Python. Explain its main properties and the methods used to add and remove elements.

10

Explain union, intersection, difference, and symmetric difference of sets using operators and methods.

11

Distinguish among subset, proper subset, superset, and disjoint sets in Python.

12

Describe practical applications of sets. Write a Python program that finds unique, common, and exclusive values in two lists.

13

Define a tuple. Explain tuple creation, packing, unpacking, indexing, and immutability.

14

Compare lists and tuples in Python. State situations in which a tuple is preferable to a list.

15

Explain extended tuple unpacking and swapping of variables with suitable Python examples.

16

Analyze immutability and hashability in relation to tuples. Under what conditions can a tuple be used as a dictionary key?

17

Define a Python dictionary. Explain how key-value pairs are created, accessed, updated, added, and deleted.

18

Explain important dictionary methods and different ways to iterate over a dictionary.

19

What is dictionary comprehension? Use it to create, transform, and filter dictionary entries.

20

Design and explain a Python program that counts word frequencies in a sentence using a dictionary, and discuss its complexity.