Anjeev Singh Academy

Anjeev Singh Academy

Class 12 Computer Science 083 Chapter 2 Python Revision Tour II Sumita Arora Book Exercise Solution

Chapter 2 – Python Revision Tour II

Type A: Short Answer Questions / Conceptual Questions

Question – 1: Internal Structure of String

Answer: In Python, Strings are stored by storing each character separately in contiguous locations.

Internal Structure of Strings in Python

The characters of strings are given two-way indices – forward direction 0, 1, 2, 3 .. size-1, and backward direction -1, -2, …, -size.

Question – 2: Program – Input String and print its two characters in different lines

Answer: Python Code-

string = input("Enter a String : ")
i=0
for j in range(1, len(string), 2):
   print(string[i:j+1])
   i += 2

Output:

Question – 3: Utility and Significance of List

Answer: List is a standard data type of Python that can store a sequence of values belonging to any type. It is depicted through square brackets.

Lists are mutable, which means we can change the element of a list in place.

Lists play a vital role in implementing stacks and queues in python.

Due to its mutability feature, you can use it at several places where you need to make changes at run time.

Question – 4: Understand by Mutability. Means of in-place

Answer: Mutability means you can change the values of elements in place.

in-place means at the same memory location.

Generally in Python, when you change the value of an immutable variable, it starts pointing to another memory location, which means changes are not done in the same memory.

While in the case of mutable variables, changes take place at the same memory, it does not start pointing to another memory location.

Question – 5: List = [8, 9, 10]. Do the following operation

(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 index 3

Answer:

(a) List[1] = 17

(b) List.extends([8,9,10])

(c) List.pop(0)

(d) List.sort()

(e) List = List * 2

(f) List.insert(3, 25)

Question – 6: List Slice

Answer: if string a is of at least two characters,

>>> a[1:1] => returns empty string ”

if string a is shorter

>>> a[1:1] => returns empty string ”

Question – 7: Two ways to add something to a list. Differentiate them

Answer: Two ways to add something to list are – (a) append( ) and (b) extend()

append() – append() add an element at the end of the list.

extend() – extend() add list of elements at the end of the list.

Example:

>>>List = [8, 9, 10]

>>> List.append(11)

>>> List

[8, 9, 10, 11]

>>> List.extend([4, 3 , 2])

>>> List

[8, 9, 10, 11, 4, 3, 2]

Question – 8: Two ways to remove something from a list. Differentiate them

Answer: Two ways to remove something from list are – (a) pop( ) and (b) remove()

pop() = pop() removes an element from a list and return it. By default, it removes the last element from a list.

pop(index_postion) will remove the element of the given index position.

remove() = remove(value) method remove the first occurrence of given item from the list. Takes one argument and does not return anything.

Difference between pop() and remove()

  • pop() can work without any argument, while remove() can not.
  • pop() remove the element on the basis of index position, while remove() removes the element on the basis of item.
  • pop() returns the value, while remove() does not return any value.
Question – 9: List vs Tuple

Answer: List vs Tuple

ListTuple
Lists are mutable.
Tuples are not mutable.

Sorry! You cannot copy content of this page. Please contact, in case you want this content.

Topics in this Post
Scroll to Top