0% found this document useful (0 votes)
11 views

Chap-2 Python Revision Tour-2

The document provides a comprehensive overview of Python data types including strings, lists, tuples, and dictionaries, detailing their properties such as mutability and indexing. It also covers sorting algorithms like bubble sort and insertion sort, along with objective type questions and assertions related to Python programming concepts. The document serves as a revision guide for students learning Python, featuring multiple choice questions and fill-in-the-blank exercises.

Uploaded by

pkg9703
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Chap-2 Python Revision Tour-2

The document provides a comprehensive overview of Python data types including strings, lists, tuples, and dictionaries, detailing their properties such as mutability and indexing. It also covers sorting algorithms like bubble sort and insertion sort, along with objective type questions and assertions related to Python programming concepts. The document serves as a revision guide for students learning Python, featuring multiple choice questions and fill-in-the-blank exercises.

Uploaded by

pkg9703
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

LET US REVISE locattons

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 &

OBJECTIVE TYPE QUESTIONS OTQs


MULTIPLE CHOCE QUESTIONS

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|

4. Following set of commands is executed in shell, what will be the output ?


>>>str = "hello"
>>>str[:2]
(a) he (b) lo (c) olleh (d) hello
5. What data type is the object below?
L= [1, 23, 'hello', 1]
(a) list (b) dictionary (c) array (d) tuple
6. What data type is the object below?
L = 1, 23, 'hello', 1
(a) list (b) dictionary (c) array () tuple
7. To store values in terms of key and value, what core data type does Python provide ?
(a) list (b) tuple (c) class (d) dictionary
8. Identify the invalid Python statemernt from the following: |CBSE D 24)
(a) d= dict() (b) e= (}
() f- U (d) g=dict[}
9. What is the value of the following expression ?
3+3.00, 3**3.0
(a) (6.0, 27.0) (b) (6.0, 9.00) (c) (6, 27) (d) [6.0, 27.0] (e) (6, 27]
10. List AL is defined as follows :

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

S You have the following code segment


Stringl "y"
String2 "work
print (Stringl String2)
What is the output of this code ?
) y Work (b) work () mywork () my
A You have the follow ing code segment
Stringin "y"
String2 "work"
orint (Stringl+ String2.upper())
What is the output of this code ?
i)mywotk (b) MY Work () myWORK () My Work
Which line of code produces an eror ?
aore" two' (b) 12 () "one" +2 () T+2
8 What is the output of this code ? » Int ("3" + "4")
() 4 () 34 () 24
1 Whih ite of cxde will cause an error ?
1. nua (5, 4, 3, (2], 1]
2. print (nu[0] )
3. print (nun(3][e])
4. print (num[5])
(9 Line 2 () Line 4 () Line 1

20 Which is te orret form of declaration ef dictionary


Day 1 Monday. 2 Tuesday, 3wednesday)
ay 1 Motav, 2. Tueay wedresday)
Dley 1 Monday 2 Tuesday wednesday ]
(Dy |mdsy, tuesday, Jwednesday'|
L dentity the valid doxlaration ot L: L[Mon, 23, hello',6.5] CBSE SP 2020-21|

string () tuple (4) list


dicticary
incorrect ?
Supgse atuple Tis declared as T (10, 12, 43, 39), which of the following is
(b) T|2] -29
peint(|ID
()printtlen(T) CISE SP 2020-213

2 Cven the following Tuple Tup (18, 20, 30, 5a)


CBSE D 23)
Rhch cd the following statetemts will result in an error ?
9print(Tup[o]) b) Tup. insert (2, 3) (O print(Tup[1:2]) () print (len(Tup) )
executing the following code ?
the follow ing statemertís) would give an error after
Staf (rugan":120, "Mithu" 195) Statenent 1
Statement 2
int (5tud(95|) $tatement 3
Stut["rugan"] 99
Statesnt 4
pr int(5tud. popt )) Statemgnt 5
pr int(5tud)
78 COMPUTER SCIENCE WITH PrTHON
(a) Statement 2 (b) Statenent 3
fo) Statement 4 () Statemerits 2 and 4
25 Whih ot the following will delete key-value pair for key "Red' from a dictiomary DI ?
(a) delete D1("Red") (b) del D1[ "Ped" ]
del.01[" Ped" ] (d) D1.del [ "Red" ] CBSE SP 2023-2
26. What does the list.remove() method do in Python?
(a) Removes the element at index I from the list
() Removes the hrst occurrence of value r from the ist
(o Removes all occurrences of value from the list
(A Removes the last occurrence of value r from the list
[CDSE SP 201242
FILL IN THE BLANKS
L Strings in Pythen store their individual letters in Memory in location.
2. Operator when used with two strings, gives aconcatenated string
3. Operator when used with a string and an integer gjves an error.
4 Part of astring containing some Contiguous characters from thestring is called
5. The operator when used with a list/string and an integer, replicates the list/string.
are not mutable whule lists are.
7 Using funchon, you can make a true copy of a list
The function is used to remove an item from a list/dictionary.
9 The statement can emOve an individual item or a slice frorn a list.
10 The funtion removes ail the elements of a listdictionary
1 Creating a tuple trom aset of vahues is called
12 Creating individual values from a tuple s elements is called
Imethoxd returrs all the keys in a dictionary
14 The furutien retums all values from Key: value pair of a dictionary
funetion retus all the Key ivalue pairs as (key, value) sequences.
TRUE/FALSE QUESTIONS
1 obtk the following represent the same list"
(', , 'c']
2Alist may contain any type ot objets except another list.
3 Thene is no conKeptual limit to the size of a
list.
4 All elements in a list
must be of the same type
3Aven obt yappear in a lst more than once
6 The keys ot a
dictionary must be of immutable types.
7 You an combine a
numeric value and a string by using the + symbol.
5 The cieart }removes al! the
elenents of a dictionary but does not delete the empty
9he mzxí } ara min ) wn used with tupleg, can work if dictionar
elements of the tuple are all of the same typ
REVISION TOUR # 79
Clapter2 pytHON
characters is similar to a string type.
10 Aist of
index n,
s[.n] + s{n] will give you original string s.
IL For any
12 Adictionary can contain keys of any valid Python types.
AssERTIONS AND REASONS
pRECTIONS
Iu te follewing questions, a statemment of Assertion (A)is followed bya statement of Reason (R).
Mark tle correct chotce as :
(a) Both A and R are true and R is the correct explanation of A.
) Both A and R are true but R is not the correct explanation of A.
c) A is true but R is false (or partlv true).
(d) A is false (or partly true) but R is true. (e) Both Aand R are false or not fully true.

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]

6. Assertion. Dictionaries are mutable but their keys are immutable.


Reason. The values of a dictionary can change but keys of dictionary cannot be changed because
through them data is hashed.
Asertion. In lnsertion Sort, a part of the array is always sorted.
Reason. In insertion sort, each successive element is picked and inserted at an appropriate position
in the sorted part of the array
CHAPTER 2 : PYTHON REVISION TOUR-||
Multiple Choice Questions
1. (C) 2. (b) 3. (c) 4. (a) 5. (a) 6. (d)
7. () 8. (d) 9. (a) 10. (a). (b), (e) 11. (b), (d) 12. (b)
13. (c) 14. (b) 15. (c) 16. (c) 17. (d) 18. (c)
19. () 20. (a) 21. (d) 22. (b) 23. (6) 24. (d)
25. (b) 26. (b)
Fill in the Blanks
1. contiguous 2. + 3. + 4. string slice 5. *

6. Tuples or Strings 7. list( ) 8. pop() 9. del 10. clear()


11. packing 12. unpacking 13. keys( ) 14. values( ) 15. itenms( )
True/False Questions
1. F 2. F 3. T 4. F 5. T 6. T
7. F 8. T 9. T 10. F 11. T 12. F
Assertions and Reasons
1. (a) 2. (c) 3. (a) 4. (d) 5. (a) 6. (a) 7. (

You might also like