Unit 3: Strings and Lists; Tuples and Dictionaries - Subjective Questions

ECE181 — Introduction To Python • Practice Questions with Detailed Answers

20 questions

1

Explain why a string is called a compound data type in Python. Illustrate with an example how individual characters can be accessed using indexing.

2

Describe how the length of a string is determined in Python. How can you use the length to access the last character safely?

3

Explain string traversal in Python. Write programs to traverse a string using both a while loop and a for loop.

4

What are string slices? Explain the slicing syntax s[start:stop:step] with suitable examples covering default values and negative indices.

5

Explain how string comparison works in Python. Describe the role of lexicographic ordering with examples.

6

Describe the find() function for strings. Explain its parameters and return values, and write a function of your own that mimics find().

7

Explain the concept of looping and counting in strings. Write a program to count the number of occurrences of a particular character in a string.

8

What are lists in Python? Explain the different types of list values they can store, and how lists differ from strings.

9

Explain membership and length operations on lists. Illustrate with the in, not in operators and the len() function.

10

Describe the various list operations in Python including concatenation, repetition, and slicing with suitable examples.

11

Explain the different ways to perform deletion of elements from a list in Python. Describe del, remove(), and pop() with examples.

12

Explain how to access elements of a list and traverse a list using for loops. Demonstrate accessing by index and by value.

13

Explain list as parameters to functions. Discuss with an example how lists are passed and why changes inside a function affect the original list.

14

What are nested lists? Explain how to create and access elements of a nested list, and write a program to print a matrix using nested lists.

15

Define a tuple. Explain how tuples are created and describe why tuples are considered immutable, comparing them with lists.

16

Explain the various operations on tuples such as indexing, slicing, concatenation, repetition, and tuple assignment (packing and unpacking) with examples.

17

What is a dictionary in Python? Explain how to create a dictionary and add, modify, and retrieve values with examples.

18

Explain how to delete items from a dictionary. Describe del, pop(), popitem(), and clear() with examples.

19

Describe the important dictionary methods in Python such as keys(), values(), items(), get(), update(), and copy() with examples.

20

Discuss the common operations on dictionaries including traversal, membership testing, and building a dictionary from data. Write a program to count the frequency of each character in a string using a dictionary.