Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
33 views9 pages

Revision Tour 2 - Strings

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)
33 views9 pages

Revision Tour 2 - Strings

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/ 9

CHAPTER 2 –REVISION TOUR – II

[STRINGS, LISTS, TUPLES, DICTIONARY]

PRACTICE QUESTIONS

STATE TRUE OR FALSE


1. String is mutable data type.
2. Python considered the character enclosed in triple quotes
as String.
3. String traversal can be done using „for‟ loop only.
4. Strings have both positive and negative indexes.
5. The find() and index() are similar functions.
6. Indexing of string in python starts from 1.
7. The Python strip() method removes any spaces or specified
characters at the start and end of a string.
8. The startswith() string method checks whether a string
starts with a particular substring.
9. "The characters of string will have two-way indexing."
ASSERTION & REASONING
1. A: Strings are immutable.
R: Individual elements cannot be changed in string in
place.
2. A: String is sequence datatype.
R: A python sequence is an ordered collections of
items where each item is indexed by an integer.
3. A: a=‟3‟
b=‟2‟
c=a+b
The value of c will be 5
R: „+‟ operator adds integers but concatenates strings
4. A:
a = "Hello"
b = "llo"
c=a-b
print(c)
This will lead to output: "He"
R: Python string does not support - operator
5. A:
str1="Hello" and str1="World" then print(str1*3) will give
error.
R : * replicates the string hence correct output will be
HelloHelloHello
6. A: str1=”Hello” and str1=”World” then
print(„wo‟ not in str) will print false
R : not in returns true if a particular substring is not
present in the specified string.
7. A: The following command >>>"USA12#'.upper()
will return False.
R: All cased characters in the string are uppercase and
requires that there be at least one cased character
8. A: Function isalnum() is used to check whether characters
in the string are alphabets or numbers.
R: Function isalnum() returns false if it either contains
alphabets or numbers
9. A: The indexes of a string in python is both forward and
backward.
R: Forward index is from 0 to (length-1) and backward
index
is from -1 to (-length)
10. A: The title() function in python is used to convert the first
character in each word to Uppercase and remaining
characters to Lowercase in the string and returns an
updated string.
R: Strings are immutable in python.
OBJECTIVE TYPE QUESTIONS (MCQ)
1. What is the output of 'hello'+1+2+3?
(a) hello123 (b) hello6 (c) Error (d) Hello+6
2. If n=”Hello” and user wants to assign n[0]=‟F‟ what will be
the result?
(a) It will replace the first character
(b It‟s not allowed in Python to assign a value to an
individual character using index
(c) It will replace the entire word Hello into F
(d) It will remove H and keep rest of the characters
3. In list slicing, the start and stop can be given beyond
limits. If it is then:
(a) Raise exception IndexError
(b) Raise exception ValueError
(c) Return elements falling between specified start and stop
values
(d) Return the entire list
4. Select the correct output of the code:
Str=“Computer”
Str=Str[-4:]
print(Str*2)
a. uter b. uterretu c. uteruter d. None of these
5. Given the Python declaration s1=”Hello”. Which of the
following statements will give an error?
(a) print(s1[4]) (b) s2=s1 (c) s1=s1[4] (d) s1[4]=”Y”
6. Predict the output of the following code:
RS=''
S="important"
for i in S:
RS=i+RS
print(RS)
7. What will the following code print?
>>> print(max("zoo 145 com"))
(a) 145 (b) 122 (c) z (d) zoo
8. Ms. Hetvee is working on a string program. She wants to
display last four characters of a string object named s.
Which of the following is statement is true?
a. s[4:] b. s[:4] c. s[-4:] d. s[:-4]
9. What will be the output of following code snippet:
msg = “Hello Friends”
msg [ : : -1]
a)Hello b) Hello Friend c) 'sdneirF olleH' d) Friend
10. Suppose str1= „welcome‟. All the following expression
produce the same result except one.Which one?
(a) str[ : : -6] (b) str[ : : -1][ : : -6] (c) str[ : :6] (d) str[0] + str[-
1]
11. Consider the string state = "Jharkhand". Identify the
appropriate statement that will display the lastfive
characters of the string state?
(a) state [-5:] (b) state [4:] (c) state [:4] (d) state [:-4]
12. Which of the following statement(s) would give an error
during execution?
S=["CBSE"] # Statement 1
S+="Delhi" # Statement 2
S[0]= '@' # Statement 3
S=S+"Thank you" # Statement 4
(a) Statement 1 (b) Statement 2
(c) Statement 3 (d) Statement 4
13. Select the correct output of the following string operations
mystring = "native"
stringList = ["abc","native","xyz"]
print(stringList[1] == mystring)
print(stringList[1] is mystring)
a) True b) False c) False d) Ture
False True Flase Ture
14. Select the correct output of the code :
n = "Post on Twitter is trending"
q = n.split('t')
print( q[0]+q[2]+q[3]+q[4][1:] )
(a)Pos on witter is rending (b)Pos on Twitter is ending
(c) Poser witter is ending (d) Poser is ending
15. What will be the result of the following command:-
>>>"i love python".capitalize()
(a) 'I Love Python' (b) 'I love python'
(c) 'I LOVE PYTHON' (d) None of the above
16. The number of element return from the partition function
is: >>>"I love to study Java".partition("study")
(a) 1 (b) 3 (c) 4 (d) 5
17. Predict the output of the following:
S='INDIAN'
L=S.partition('N')
G=L[0] + '-' + L[1] + '-' + L[2]
print(G)
(a) I-N-DIA-N (b) I-DIA- (c) I-DIAN (d) I-N-DIAN
18. What will be the output of the following command:
>>>string= "A quick fox jump over a lazy fox"
>>>string.find("fox",9,34)
(a) 28 (b) 29 (c) 8 (d) 7
19. Select the correct option for output
X="abcdef"
i='a'
while i in X:
print(i, end=" ")
(a) Error (b) a (c) infinite loop (d) No output
20. What is the output of the following code?
S1="Computer2023"
S2="2023"
print(S1.isdigit(), S2.isdigit())
a)False True b) False False
c) True False d) True True
21. What will be the output of the following statement given:
txt="cbse. sample paper 2022"
print(txt.capitalize())
a) CBSE. sample paper 2022 b) CBSE. SAMPLE SAPER
2022
c) cbse. sample paper 2022 d) Cbse. Sample Paper 2022
22. Select the correct output of the code:
a = "Year 2022 at all the best"
a = a.split('a')
b = a[0] + "-" + a[1] + "-" + a[3]
print (b)
a) Year – 0- at All the best b) Ye-r 2022 -ll the best
c) Year – 022- at All the best d) Year – 0- at all the best
23. Select the correct output of the code:
mystr = „Python programming is fun!‟
mystr = mystr.partition('pro')
mystr='$'.join(mystr)
(a) Python $programming is fun!
(b) Python $pro$gramming is fun!
(c) Python$ pro$ gramming is fun!$
(d) P$ython $p$ro$gramming is $fun!
24. Identify the output of the following Python statement:
s="Good Morning"
print(s.capitalize( ),s.title( ), end="!")
(a) GOOD MORNING!Good Morning
(b) Good Morning! Good Morning
(c) Good morning! Good Morning!
(d) Good morning Good Morning!
25. What is the output of the following code?
Str1="Hello World"
Str1.replace('o','*')
Str1.replace('o','*')
(a) Hello World (b) Hell* W*rld
(c) Hello W*rld (d) Error
26. State whether the statement is True or False?
No matter the underlying data type, if values are equal
returns true.
27. Predict the output of the following:
S="Hello World!"
print(S.find("Hello"))
(a) 0 (b) 3 (c) [2,3,7] (d) (2,3,7)
28. Which of the following is not a valid Python String
operation?
(a) 'Welcome'+'10' (b)'Welcome'*10
(c) 'Welcome'*10.0 (d) '10'+'Welcome'
29. Which of the following statement(s) would give an error
after executing the following code?
EM = "Blue Tick will cost $8" # Statement 1
print( EM) # Statement 2
ME = "Nothing costs more than Truth" # Statement 3
EM *= 2 # Statement 4
EM [-1: -3 : -1] += ME[ : 7] # Statement 5
(a) Statement 3 (b) Statement 4
(c) Statement 5 (d) Statement 4 and 5
30. Select the correct output of the following code :
s="I#N#F#O#R#M#A#T#I#C#S"
L=list(s.split("#"))
print(L)
(a) [I#N#F#O#R#M#A#T#I#C#S]
(b) [„I‟, „N‟, „F‟, „O‟, „R‟, „M‟, „A‟, „T‟, „I‟, „C‟, „S‟]
(c) ['I N F O R M A T I C S']
(d) ['INFORMATICS']
31. STRING="WELCOME" #Line1
NOTE= " " #Line2
for S in range[0,8] #Line3
print(STRING[S]) #Line4
print(S STRING) #Line5
Which statement is wrong in above code:
a) Line3 and Line4 b) Line4 and Line5
c) Line2 and Line3 d) Line3 and Line5
32. Consider the following code that inputs a string and
removes all special characters from it after converting it to
lowercase.
s = input("Enter a string")
s = s.lower()
for c in ',.;:-?!()\'"':
_________________
print(s)
For eg: if the input is 'I AM , WHAT I AM", it should print
i am what i am
Choose the correct option to complete the code .
a. s = s.replace(c, ' ') b. s = s.replace(c, '\0')
c. s = s.replace(c, None) d. s = s.remove(c)
33. Which of the following statement(s) would give an error
after executing the following code?
str= "Python Programming" #S1
x= '2' #S2
print(str*2) #S3
print(str*x) #S4
(a) S1 (b) S2 (c) S3 (d) S4
2 –MARKS / 3 - MARKS
1. If S="python language" is a Python string, which method
will display the following output 'P' in uppercase and
remaining in lower case?
2. Rewrite the following code :
for Name in [Aakash, Sathya, Tarushi]
IF Name[0]= 'S':
print(Name)
3. Consider the given Python string declaration:
>>> mystring = 'Programming is Fun'
>>> printmystring[-50:10:2].swapcase())
4. Rewrite the following:
STRING=""WELCOME
NOTE = " "
for S in range(0,8):
if STRING[S]= ‟E‟:
print(STRING(S))
Else:
print "NO"
5. Given is a Python string declaration:
>>>Wish = "## Wishing All Happy Diwali @#$"
Write the output of >>>Wish[ -6 : : -6 ]
6. Predict the output of the following:
Name = "cBsE@2051"
R=" "
for x in range (len(Name)):
if Name[x].isupper ( ):
R = R + Name[x].lower()
elif Name[x].islower():
R = R + Name[x].upper()
elif Name[x].isdigit():
R = R + Name[x-1]
else:
R = R + "#"
print(R)
7. Predict the output of the following:
>>> 'he likes tea very much'.rstrip('crunch')
>>> 'There is a mango and an apple on the table'.rstrip('ea')
7. Find the output
Msg1="WeLcOME"
Msg2="GUeSTs"
Msg3=""
for I in range(0,len(Msg2)+1):
if Msg1[I]>="A" and Msg1[I]<="M":
Msg3=Msg3+Msg1[I]
elif Msg1[I]>="N" and Msg1[I]<="Z":
Msg3=Msg3+Msg2[I]
else:
Msg3=Msg3+"*"
print(Msg3)
8. Predict the output of the following:
s="3 & Four"
n = len(s)
m=""
for i in range(0, n):
if (s[i] >= 'A' and s[i] <= 'Z'):
m = m +s[i].upper()
elif (s[i] >= 'a' and s[i] <= 'z'):
m = m +s[i-1]
if (s[i].isdigit()):
m = m + s[i].lower()
else:
m = m +'-'
print(m)
9. Name="PythoN3.1"
R=" "
for x in range(len(Name)):
if Name[x].isupper():
R=R+Name[x].lower()
elif Name[x].islower():
R=R+Name[x].upper()
elif Name[x].isdigit():
R=R+Name[x-1]
else:
R=R+"#"
print(R)
10. Find output generated by the following code:
string="aabbcc"
count=3
while True:
if string[0]=='a':
string=string[2:]
elif string[-1]=='b':
string=string[:2]
else:
count+=1
break
print(string)
print(count)
11. Write the output of the code snippet.
txt = "Time, will it come back?"
x = txt.find(",")
y = txt.find("?")
print(txt[x+2:y])
12. Predict the output of the following:
S='Python Programming'
L=S.split()
S=','.join(L)
print(S)
13. Predict the output of the following:
S="Good Morning Madam"
L=S.split()
for W in L:
if W.lower()==W[::-1].lower()
print(W)
*********************************************************

You might also like