String MCQ in Python – 2

Q1) What is the output of the given below program?

string = "Know Program"
print(len(string))

a) 11
b) 12
c) 6
d) Error

View Answer Answer:- b) 12

Q2) If a class defines the str(self) method, for an object obj for the class, you can use which command to invoke the str method.

a) obj.str()
b) str(obj)
c) print obj
d) all of the mentioned

View Answer Answer:- d) all of the mentioned

Q3) Which method should I use to convert String “Python programming is fun” to “Python Programming Is Fun”?

a) capitalize()
b) title()
c) istitle()
d) upper()

View Answer Answer:- b) title()

Q4) Choose the correct function to get the character from the ASCII number.

a) chr(number)
b) char(number)
c) ascii(number)

View Answer Answer:- a) chr(number)

Q5) Choose the correct function to get the ASCII code of a character.

a) ord(‘char’)
b) char(‘char’)
c) ascii(‘char’)

View Answer Answer:- a) ord(‘char’)

Q6) In Python3, Whatever you enter as input, the input() function converts it into a string.

a) True
b) False

View Answer Answer:- a) True

Q7) To check whether string s1 contains another string s2, use __.

a) s1.contains(s2)
b) s2 in s1
c) s1.contains(s2)
d) si.in(s2)

View Answer Answer:- a) s1.contains(s2)

Q8) Which of the following function convert a string to a float in python?

a) int(x [,base])
b) long(x [,base] )
c) float(x)
d) str(x)

View Answer Answer:- c) float(x)

Q9) What does the function re.match do?

a) matches a pattern at the start of the string
b) matches a pattern at any position in the string
c) such a function does not exist
d) none of the mentioned

View Answer Answer:- a) matches a pattern at the start of the string

Q10) Python does not support a character type; a single character is treated as strings of length one.

a) True
b) False

View Answer Answer:- a) True

Also See:- MCQ on String in Python– 3

Leave a Comment

Your email address will not be published.