0% found this document useful (0 votes)
448 views2 pages

Vision International School of Excellence Class: 11 CHAPTER-: List Manipulation

This document contains 12 questions and answers about Python lists. It discusses the utility of lists, how they are mutable and can contain elements of different types. It also covers list functions like append, remove, sorting, slicing, copying lists, and how indexing works differently for individual elements versus slices. Lists are compared to strings, noting that lists can contain heterogeneous elements and are mutable while strings are immutable.

Uploaded by

saroj mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
448 views2 pages

Vision International School of Excellence Class: 11 CHAPTER-: List Manipulation

This document contains 12 questions and answers about Python lists. It discusses the utility of lists, how they are mutable and can contain elements of different types. It also covers list functions like append, remove, sorting, slicing, copying lists, and how indexing works differently for individual elements versus slices. Lists are compared to strings, noting that lists can contain heterogeneous elements and are mutable while strings are immutable.

Uploaded by

saroj mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

VISION INTERNATIONAL SCHOOL OF EXCELLENCE

Class: 11th CHAPTER-: List Manipulation

Q.1.Discuss the utility and significance of Lists, briefly?


Ans:- Lists in Python are used to store elements which can be stored in a single variable.
They are analogous to arrays from other programming languages. They are mutable
and hence their elements can be changed. They can also store elements of different
types. E.g.
A=[True, 56, ‘peace’]
Element in the list can be added and removed via
a.append(5) #To add a new element in a list
a.remove(56) #To remove something from list

Q.2.What do you understand by mutability? What does” in Place” memory updation


mean?
Ans:- An object's mutability is determined by its type. Some objects like lists and
dictionaries are mutable , it means we can change their content without changing their
identity. Other objects like integers, floats, strings and tuples are objects that can not
be changed.

Q.3. Start with the list [8,9,10]. Do the following using list funcrion:
(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
(d) sort the list
(e) Double the list
(f) Insert 25 at index 3
Ans3:-
l=[7,8,9]
(a) l[1]=17 #l becomes[7,17,9]
(b) l.extend9[4,5,6]) #l becomes[7,17,9, 4,5,6]
(c) l.pop(0) #l becomes[17,9, 4,5,6]
(d) l.sort() #l becomes[4,5,6,9,17]
(e) l=2*l #l becomes[4,5,6,9,17, 4,5,6,9,17]
(f) l[3]=25 #l becomes[4,5,6, 13,17, 4,5,6,9,17]

Q.5: What’s a [1:1] if a is a string of at least two character? And what if string is
shorter?
Ans:-a [l:r] will output the characters from index l to r-1.
So, if a is a string, a[1:1] will be an empty string because l and r are both equal. Therefor
if a string has at least two characters or not, a [1:1] will be “”(empty string).

Q.6. What is the purpose of del operator and pop method? Try deleting a slice.
Ans: Del and pop both are use to remove an element from the list. The difference is that
pop returns the element that is being removed and del does not. E.g
a=[1,2,3]
a.pop(0) will return 1
del can delete list slices e.g.
a=[1,2,3,4,5,6]
del a[0:2]
print(a) #[3,4,5]

Computer Science CH-5, String Manipulation,, Class 11 (By: SAROJ MEHTA) | Page 1 of 2
Q.7. What does each of the following expressions evaluate to ? Suppose that L is the
list.
[“These”,[“are”, “a”, “few”, “words”], “that”, “we” “will” , “use”].
(a) L[1][0::2]
(b) “a” in L[1][0]
(c) L[:1]+L[1]
(d) L[2::2]
(e) L[2][2] in L[1]
Ans:-
(a). [‘are’, ‘few’]
(b). True
(c). [‘these’, ‘are’, ‘a’, ‘few’, ‘words’]
(d) [‘that’ , ‘will’]
(e). True

Q.8. What are list slices? What for can you use them?
Ans: A list slices in Python refers to a prat of the list which is extracted from another
list. It is a list containing some contagious element of another list. The syntax is :
Listvariable[startingIndex : EndingIndex].

Q.9:- Does the slice operator always produce a new line?


Ans: The slice operator always produces a copy of the part of the list that is being slice.
Even the whole original list can be produced using slicing. E.g.
A=[1,2’3’4]
A[0:] will return the whole list

Q.10. Compare lists with strings. How are they similar and how are they different ?
Ans:-The similarity between list and string is that they both are a sequence. But list is a
sequence of elements of the same of different types where as string is a sequence of
characters all of which are string type. List are mutable where as srings are immutable.
So the elements in a list can be changed while the characters in a string can’t be
changed but whole string can be changed.

Q.11. What do you understand by true copy of a list? How is it different from
shallow copy?
Ans:-In case of true copy, changes made in one list do not reflect in the other one. E.g.
a=[1,2,3,4]
b=list(a)
a[0]=5
print(b) # ‘b’ is still [1,2,3,4] even though ‘a’ has becobe[5,2,3,4]
shallow copy is useful for compound objects only, i.e a list containing other lists. A
shallow copy constructs a new compound object and then inserts references into it to
the objects found in the original.

Q.12. An index out of bounds given with a list name causes error, but not with list
slices. Why?
Ans:- Slicing returns a list, if the indices don’t fall within the range of the number of
elements in the list, we can return an empty list, so there is no need to throw an error
but while accessing an element using an index, if the index is out of range, we can’t
return a default value like none(because it could be a valid value in the list), so an error
is thrown.
Hence if a=[1,2,3,4]
a[4] will return an error but a[4:5] won’t

Computer Science CH-5, String Manipulation,, Class 11 (By: SAROJ MEHTA) | Page 2 of 2

You might also like