Unit 3: String, Lists, Tuples and Dictionaries - Subjective Questions

INT108 — Python Programming • Practice Questions with Detailed Answers

20 questions

1

Explain why a Python string is called a compound data type. Describe how individual characters are accessed, including the use of positive and negative indices.

2

Describe how the length of a string is determined in Python. Write a program that traverses a string and displays each character with its index.

3

Explain string slicing in Python. What do the expressions text[start:stop:step], text[:], text[::-1], and text[2:7:2] represent?

4

How are strings compared in Python? Explain lexicographical comparison, case sensitivity, and the role of Unicode values with suitable examples.

5

Explain the purpose and syntax of the string find() method. How can its return value be used safely in a program?

6

Develop and explain a Python program that uses looping and counting to determine the frequencies of all characters in a string, ignoring letter case.

7

Define a Python list. Explain list values, list length, element access, and membership testing with examples.

8

Describe the major list operations in Python, including concatenation, repetition, appending, insertion, extension, and element replacement.

9

Explain list slicing and slice assignment. How do these operations differ from string slicing?

10

Compare the different ways of deleting elements from a list using del, pop(), remove(), and slice assignment.

11

Explain how for loops are used with lists. Write a program to calculate the sum, average, minimum, and maximum of a non-empty numeric list without using sum(), min(), or max().

12

Explain how lists behave when passed as parameters to functions. Distinguish between modifying a list and rebinding a parameter to a new list.

13

What is a nested list? Explain how elements are accessed and traversed in a two-dimensional list representing a matrix.

14

Distinguish between lists and tuples with special reference to mutability, syntax, operations, and appropriate use cases.

15

Explain tuple packing, tuple unpacking, and simultaneous tuple assignment. Show how tuple assignment can swap two values without a temporary variable.

16

How can tuples be used as return values from functions? Write and explain a function that returns both the quotient and remainder of integer division.

17

Describe the fundamental dictionary operations in Python, including creation, access, insertion, update, membership testing, and deletion.

18

Explain the purpose of the dictionary methods keys(), values(), items(), get(), update(), setdefault(), pop(), and clear().

19

Explain how a dictionary can be used to represent a sparse matrix. Compare this representation with a conventional nested-list matrix.

20

Explain aliasing and copying in Python lists. Distinguish assignment, shallow copying, and deep copying, especially for nested lists.