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

Python String MCQ With Answers & Explanation - Letsfindcourse

Its a very useful resource

Uploaded by

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

Python String MCQ With Answers & Explanation - Letsfindcourse

Its a very useful resource

Uploaded by

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

!

Python MCQ Topics


About & History

Python Basics

Data Types

Variables & Operators

Conditionals & Loops

Functions

Arguments

String

Python List

Python Tuple

Python Dictionary

Python Sets

Python OOPs

Classes & Objects

Inheritance

Regular Expression

Exception Handling

Python Reference
Learn Python

Python Interview Question

Python Quiz

Python Books

Top 5 Python Courses

Other Reference
Quantitative Aptitude

Learn Django

Data Science Books

Data Science online course


Industry oriented modules & project exposure. Enroll for Free Demo.
250+ Hiring Partners.

Ad datascience.cranesvarsity.com Visit Site

Pluralsight 33% OFF - End of Year Sale!! ×

Python String MCQ


This section focuses on the "String" in
Python. These Multiple Choice Questions
(mcq) should be practiced to improve the
Python skills required for various
interviews (campus interview, walk-in
interview, company interview), placement,
entrance exam and other competitive
examinations.

1. What will be the output of above


Python code?

str1="6/4"

print("str1")

A. 1
B. 6/4
C. 1.5
D. str1

View Answer
Ans : D
Explanation: Since in print statement, str1 is
written inside double quotes so it will simply print
str1 directly.

2. Which of the following will result in


an error?

str1="python"

A. print(str1[2])
B. str1[1]="x"
C. print(str1[0:9])
D. Both (b) and (c)

View Answer
Ans : B
Explanation: Strings are immutable. So,new
values cannot be assigned at any index position
in a string

3. Which of the following is False?


A. String is immutable.
B. capitalize() function in string is used to
return a string by converting the whole given
string into uppercase.
C. lower() function in string is used to return
a string by converting the whole given string
into lowercase.
D. None of these.

View Answer
Ans : B
Explanation: capitalize() function in string gives
the output by converting only the first character of
the string into uppercase and rest characters into
lowercase.However, upper() function is used to
return the whole string into uppercase.

4. What will be the output of below


Python code?

str1="Information"

print(str1[2:8])

A. format
B. formatio
C. orma
D. ormat

View Answer
Ans : A
Explanation: Concept of slicing is used in this
question. In string slicing,the output is the
substring starting from the first given index
position i.e 2 to one less than the second given
index position i.e.(8-1=7) of the given string str1.
Hence, the output will be "format".

जुनून, स्टाइल, िक्रएिटिवटी, िवरासत, िविवधता:


इटली लाजवाब है। #beIT
#beIT

sponspored by: Madeinitaly READ MORE

5. What will be the output of below


Python code?

str1="Aplication"

str2=str1.replace('a','A')

print(str2)

A. application
B. Application
C. ApplicAtion
D. applicAtion

View Answer
Ans : C
Explanation: replace() function in string is used
here to replace all the existing "a" by "A" in the
given string.

6. What will be the output of below


Python code?

str1="poWer"

str1.upper()

print(str1)

A. POWER
B. Power
C. power
D. poWer

View Answer
Ans : D
Explanation: str1.upper() returns the uppercase of
whole string str1. However,it doesnot change the
string str1. So, output will be the original str1.

7. What will the below Python code will


return?

If str1="save paper,save plants"

str1.find("save")

A. It returns the first index position of the first


occurance of "save" in the given string str1.
B. It returns the last index position of the last
occurance of "save" in the given string str1.
C. It returns the last index position of the first
occurance of "save" in the given string str1.
D. It returns the first index position of the
first occurance of "save" in the given string
str1.

View Answer

8. What will the below Python code will


return?

list1=[0,2,5,1]

str1="7"

for i in list1:

str1=str1+i

print(str1)

A. 70251
B. 7
C. 15
D. Error

View Answer

9. Which of the following will give


"Simon" as output?

If str1="John,Simon,Aryan"

A. print(str1[-7:-12])
B. print(str1[-11:-7])
C. print(str1[-11:-6])
D. print(str1[-7:-11])

View Answer

10. What will following Python code


return?

str1="Stack of books"
print(len(str1))

A. 13
B. 14
C. 15
D. 16

View Answer

Data Science online course


Master your skills & start
your career as Data
Scientist. Online/OGine
sessions.

Ad datascience.cranesvarsity.com Visit Site

Discussion

Your comments

* You must be logged in to add comment.

SUBMIT

!"#$%&'()*'*+,-#.%&-'%&'/0#0'1"2,-

!"#$%&'()*'*+,-#.%&-'%&'3&$,4.#0&5,

!"#$%&'()*'*+,-#.%&-'6'7&-8,4-'%&'9+&5#.%&-

!"#$%&':0-.5-'()*';.#$'7&-8,4-'6'<=2>0&0#.%&

?&>.&,'!"#$%&'!4%@40AA.&@'*+.B

!"#$%&'()*'*+,-#.%&-'%&')%&C.#.%&0>-'6'D%%2-

!"#$%&'()*'*+,-#.%&-'E'F.-#%4"'6'7G%+#

!"#$%&'/.5#.%&04"'()*';.#$'7&-8,4-'6
<=2>0&0#.%&

!"#$%&'()*'*+,-#.%&-'%&')>0--,-'0&C'?GH,5#-

!"#$%&'D.-#'()*';.#$'7&-8,4-'6'<=2>0&0#.%&

)%A2+#,4'I5.,&5,'()*'*+,-#.%&-'6'7&-8,4-

!"#$%&'()*'%&')%&C.#.%&0>-'0&C'D%%2-

Blogs

Copyright © 2021 Letsfindcourse

Disclosure: This page may


contain affiliate links, meaning
when you click the links and
make a purchase, we receive a
commission.

You might also like