KEMBAR78
MCQ String | PDF | Python (Programming Language) | Computing
0% found this document useful (0 votes)
40 views3 pages

MCQ String

H

Uploaded by

lakra.2181
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)
40 views3 pages

MCQ String

H

Uploaded by

lakra.2181
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/ 3

MCQ: STRING MANIPULATION

1. 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
2. Which of the following statement(s) would give an error after executing the following code?
str= “Python Programming” #statement 1
x= ‘2’ #statement 2
print(str*2) #statement 3
print(str*x) #statement 4
a) statement 1 b) statement 2 c) statement 3 d) statement 4
3. Select the correct output of the code:
Str = "KENDRIYA VIDYALAYA SANGATHAN JAMMU REGION"
Str = Str.split()
NewStr = Str[0] + "#" + Str[1] + "#" + Str[4]
print (NewStr)
a) KENDRIYA#VIDYALAYA#SANGATHAN# JAMMU b) KENDRIYA#VIDYALAYA#SANGATHAN
c) KENDRIYA#VIDYALAYA# REGION d) None of these
4. Which of the following statement(s) would give an error after executing the following code?
P ="FIRST PRE BOARD" # Statement 1
print(P) #Statement 2
P = P[1:7] + "Questions" # Statement 3
P[0] = '&' # Statement 4
P =P + "Over" # Statement 5
(a) Statement 3 b) Statement 4 (c) Statement 5 d) Statement 4 and 5
5. What is the output of the following?
print('KV Sangathan'.split('an'))
(a) ['KV S', 'gath', ' '] (b) [‘KV Sangathan’,’an’] (c) [‘KV’,’Sang’,’athan’] (d) All of them
6. If the following code is executed, what will be the output of the following code?
name="Kendriya Vidyalaya Sangathan"
print(name[10:19])
(a) Kendriya (b) Vidyalaya (c) Sangathan (d) idyalaya

7. What is the output of the following code.


str1=”Hello World”
str1.replace('o','*')
(a) Hello World (b) Hell* W*rld (c) Hello W*rld (d) Error
8. What is the output of ‘hello’+1+2+3?
a) hello123 b) hello6 c) Error d) Hello+6
9. Which statement is wrong in below code:
STRING=“WELCOME” #Line1
NOTE= “ ” #Line2
for S in range[0,8]: #Line3
print(STRING[S]) #Line4
print(S STRING) #Line5
a) Line3 and Line4 b) Line4 and Line5 c) Line2 and Line3 d) Line3 and Line5

AMIT KUMAR KUSHWAHA Page 1


10. 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!
11. (c) Python$ pro$ gramming is fun!$ (d) P$ython $p$ro$gramming is $fun!
What gets printed when the following code is executed?
names = [‘Hasan’,’Balwant’,’Sean’,’Dia’]
print(names[-1][-1])
(a) h (b) n (c) a (d) Dia
12. Select the correct output of the following string operations
mystring = “Pynative”
stringList = [ “abc”, “Pynative”,”xyz”]
print(stringList[1] == mystring)
print(stringList[1] is mystring)
a)True b) False c) False d) True
False True False True
13. Which function is used to remove the given characters from trailing end i.e. right end of a string?
(a) strip( ) (b) remove( ) (c) lstrip( ) (d) rstrip( )
14. Predict the output of following python code.
SS="PYTHON"
print( SS[:3:])
(a) THON (b) PYT (c) PYTH (d) HON
15. Predict the output of following python 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’]
16. Which of the following statement(s) would give an error after executing the following code?
S="Welcome to class XII" # Statement 1
print(S) # Statement 2
S="Thank you" # Statement 3
S[0]= '@' # Statement 4
S=S+"Thank you" # Statement 5
(a) Statement 3 (b) Statement 4 (c) Statement 5 (d) Statement 4 and 5
17. Identify the output of the following code snippet:
text = "PYTHONPROGRAM"
text=text.replace('PY','#')
print(text)
(a) #THONPROGRAM (b) ##THON#ROGRAM (c) #THON#ROGRAM (d) #YTHON#ROGRAM
18. What is the output of the expression?
country='International'
print(country.split("n"))
(a) ('I', 'ter', 'atio', 'al') (b) ['I', 'ter', 'atio', 'al'] (c) ['I', 'n', 'ter', 'n', 'atio', 'n', 'al'] (d) Error
19. Select the correct output of the code:
>>> s='mail2kv@kvsangathan.kvs.in'
>>> s=s.split('kv')
>>> op = s[0] + "@kv" + s[2]
>>> print(op)

AMIT KUMAR KUSHWAHA Page 2


(a) mail2@kvsangathan (b) mail2@sangathan. (c) mail2kvsangathan. d) error
20. Select the correct output of the following python code:
str="My program is program for you"
t = str.partition("program")
print(t)
a) ('My ', 'program', ' is ', 'program', ' for you') b) ('My ', 'program', ' is program for you')
c) ('My ', ' is program for you') d) ('My ', ' is ', ' for you')
21. Which of the following operations on a string will generate an error?
a) "PYTHON"*2 b) "PYTHON" + "10" c) "PYTHON" + 10 d) "PYTHON" + "PYTHON"
22. select the corect output of the code:
for i in "QUITE":
print([i.lower(), end="#")
a) q#u#i#t#e# b) ['quitet#"] c) ['q']#['u']#['i']#['t']#['e']# d) ['quite']#
23. Select the correct output of the code:
a = "assistance"
a = a.partition('a')
b = a[0] + "-" + a[1] + "-" + a[2]
print (b)
a) -a-ssistance b) -a-ssist-nce c) a-ssist-nce d) -a-ssist-ance
24. 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
25. Which function cannot be used with string type data?
a) min() b) max() c) count() d) sum()
26. Select the correct output of the code:
s = "Question paper 2022-23"
s= s.split('2')
print(s)
(a) ['Question paper ', '0', '', '-', '3'] (b) ('Question paper ', '0', '', '-', '3')
(c) ['Question paper ', '0', '2', '', '-', '3'] (d) ('Question paper ', '0', '2', '', '-', '3')

27. Which of the following statement(s) would give an error after executing the following code?
S="Welcome to my python program" # Statement 1
print(S) # Statement 2
S="Python is Object Oriented programming" # Statement 3
S= S * “5” # Statement 4
S=S+"Thank you" # Statement 5
(a) Statement 3 (b) Statement 4 (c) Statement 5 (d) Statement 4 and 5
28. What will be the output of the following code
string= "it goes as-ringa ringa roses"
sub="ringa"
print(string.find(sub,15,22))
(a) 13 (b)-13 (c) -1 (d) 17
29. Consider the string state = “Jharkhand”. Identify the appropriate statement that will display the last
five characters of the string state?
(a) state [-5:] (b) state [4:] (c) state [:4] (d) state [:-4]

AMIT KUMAR KUSHWAHA Page 3

You might also like