Chap-2 Python Revision Tour-2
Chap-2 Python Revision Tour-2
haroters in cotiquous
stored in memory by storing individuol the sirn
o Python strings are sometime) is the mumbered posilionof oletter in ta-lenqth in she
called subsript 1,2, up
Ihe index (ulso forward direcion up to length
1 Gnd
begin 0 onwards in the
& In Python, indices wo- way indexing. extendingup to bit
backward direction. This is called atstart ond
of the string sfsturt:end| is the element beqining
part
The string slicerefersto a
inchuding end. is in place.
mutable sequences of Python Le, you can change clements of a
Lists are
srings, Le, two wuy indexing. elemets but they are
o Lists (ndex their clements just like sliing and accessing individsal
many ways like indexing,
Lists are similar to strings in
different in the sense that Lists are mutable while strings are not opposite
an elementis present in the sequence or not end not in does the
Membership operator in tells if
shce is a list in iself
List slice is an extracted partof a list; ist stop, not including stop
creates a list slice out of ist L with clements falling between indexes startand
L[start:stop]
immutable sequences of Python L.e., you coinot chanqe elements of a uple in ploce
Tuples are
comma-separated expressions in round brockets The empty round brackets ie., 0
Tocreate atuple, put a nuniber of
indicate an empty tuple.
two way indexing
Tuples index their elenents just like strings or lists, Le, than others, they
in memory exactly like strinqs, except that becausesome of their objects are larger
4 Tuples are stored
characLer as in srings.
store areference at each index insteud of single
tuple in itself
Tuple slice is an extracted part of tuple, tuple slice is a including
creates a tuple shce out of tuple T with elements folling between indexes start ad stop, not
3 T|start:stop
stop.
key:value pair that associgte keys to values.
Dictionaries are mutable with elements in the form of a
The keys of a dictionary must be of immutable types. specific order.
Python dictionaries, the elements (key:value pairs) are unordered ; one cannot occess elemeit as per
In
3 Keys of a dictionary must be unique.
updation and addition of elements are similar in syntax. But for addition, the key must not exist in
In Dictionaries, the
the dictionary.
the dictionary and for updation, the key must exist in
elements in d specified order.
Sorting of an array means arranging the array
exchanged if they are not in proper order. Thisprocess is
In bubble sort, the adjoining values are compared and
repeated until the entire array is sorted.
inserted at an appropriate psition in the prevtously sorted array
In insertion sort,each successive element is picked &
string is called
1. The numbered position of a letter in a (d) location
(a) position (b) integer position () index
2. The operator tells if an element is present in a sequence or not.
(c) into (d) inside
(a) exists (b) in
3. The keys of a dictionary must be of types.
(b) mutable (c) immutable (d) any of these
(a) integer
76 COMPUTER SCIENCE WITH PYTHON XI|
AL = (1, 2, 3, 4, 5]
Which of the following statements removes the middle element 3 from it so that the list AL equals
[1, 2, 4, 5] ?
(a) del a(2] (b) a[2:3] =|[| (c) a[2:2] =|| (d) a[2] =[U (e) a.remove(3)
11. Which two lines of code are valid strings in Python ?
(a) This is a string (b) This is a string
(c) (This is a string) (d) "This is a string"
12. Consider the statements given below and then choose the correct
output from the given options :
myStr = "MISSISSIPPI"
print (myStr[ :4] +"#" *myStr[-5:]) |CBSE D 24|
(a) MISSI#SIPPI (b) MISS#SIPPI
(c) MISS#IPPIS (d) MISSI#IPPIS
13. Identify the statement from the following which will raise an error :
(a) print ("A" *3) (6) print (5*3)
(c) print ("15" +3)
14. Select the correct (d) print ("15" + "13") [CBSE D 24]
output of the following code :
event "G29 Presidency@2023"
L= event.split()
print (L[::-2])
(a) 'G20'
() (b) ('Presidency@2923']
('G20'] (d) 'Presidency@2023'
|CBSE D 24]
2PTHON REVISION TOUP 77
1 Assertion Lists and Tuples are similar sequence types of Python, yet they are two different dataty pes.
Reason. List sequences are mutable and Tuple sequences are immutable.
2. Asertion. Modifying a string creates another string internally but modifying a list does not reate a
wlist
Reason. Strings store characters while lists can store any type of data.
3. Aswerticn. Modifying a string creates another string internally but modifying a list does not create a
new list.
Reaon. Strings are immutable types while lists are mutable types of Python.
4AsMertion Dictionaries are mutable, hence its keys can be easily changed.
Reason Mutability means avalue can be changed in place without having to create new storage
for the changed value.
5 Assertion (A) The expression "HELLO".sort () in Python will give an error.
Reason (R) sort () does not exist as a method/tunction for strings in Python. |CESE D 24]