Chapter 2 Python Revision Tour -II Solution

Type A : Short Answer Questions / Conceptual Questions

1. What is the internal structure of Python strings?

2. Write a python script that traverses through an input string and prints its characteristics in different lines – two character per string

3. discuss the utility and significance of List, briefly.

4. What do you understand by mutability? What does “in place” task mean?

5. Start with a list [8,9,10]. Do the followings:
a. Set the second entry (index 1) to 17
b. Add 4,5 and 6 to the end of the list
c. Remove the first entry from the list
d. Sort the list
e. Double the list
f. Insert 25 at the index 3

6. what’s a[1:1] if a is a string of at least two characters ? and what if string is sorter?
Ans: Will produce empty listin both cases.

7. what are the two ways to to add something in a list? How are they different?

8. what are the two ways to remove something from a list? how are they different?

9. what is difference between a list and a tuple?

10. in the python shell do the following.
a. define a variable named state that is an empty list
b. add ‘Delhi’ to the list
c. now add ‘Punjab’ to the end of list
d. define a variable states2 that is initialized with ‘Rajasthan’, ‘Gujarat’ and ‘Kerala’.
e. add ‘Odisha’ to the beginning of the list.
f. add ‘Tripura’ so that it third state in the list
g. add ‘Haryana’ to the list so that it appears before ‘Gujarat’. do this as if you DO NOT KNOW where ‘Gujarat’ is in the list
h. remove the 5th state from the list and print that state’s name.

11. discuss the utility and significance of tuple.

12. if a is (1,2,3)
(a) what is the difference (if any) between a*3 and (a,a,a) ?
(b) is a*3 equivalent to a + a + a
(c) what is the meaning of a[1:1]
(d) what is the difference between a[1:1] and [1:2]

13. what is the difference between (30) and (30,)
Ans: (30) represent a normal integer type value and (30,) represent a tuple type value.

14. why is a dictionary termed as an unordered collection of objects?

15. what type of object can be used as keys in dictionaries?

16. Though tuples are immutable type, yet they cannot always be used as keys in a dictionary. what is the condition to use tuples as a key in a dictionary?

17. Dictionary is a mutable type, which means you can modify its contents ? What all is modifiable in a dictionary ? Can you modify the keys of a dictionary?

18. How del D and del D[<key>] different from one another if D is a dictionary?
Ans: deel D deletes dictionary completely from the memory and D[<key>] deletes only specified key and its values from the dictionary.

19. Create a dictionary named with three entries, for key ‘a’, ‘b’ and ‘c’. What happened if you try to index a nonexistent key (D[‘d’]) ? What does python do if you try to assign to a nonexistent key d.
e.g. D[‘d’]=‘spam’

20. What is sorting ? Name some popular sorting techniques.

21. Discuss bubble sort and insertion sort techniques

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!