250+ TOP MCQs on Python Strings and Answers

Python Technical Interview Questions & Answers on “Strings”.

1. What will be the output of the following Python statement?

a) A
b) B
c) a
d) Error
Answer: a
Clarification: Execute in shell to verify.

2. What will be the output of the following Python statement?

  1. >>>print(chr(ord('b')+1))

a) a
b) b
c) c
d) A
Answer: c
Clarification: Execute in the shell to verify.

3. Which of the following statement prints helloexampletest.txt?
a) print(“helloexampletest.txt”)
b) print(“hello\example\test.txt”)
c) print(“hello”example”test.txt”)
d) print(“hello”example”test.txt”)
Answer: b
Clarification: is used to indicate that the next is not an escape sequence.

4. Suppose s is “ttWorldn”, what is s.strip()?
a) ttWorldn
b) ttWorldn
c) ttWORLDn
d) World
Answer: d
Clarification: Execute help(string.strip) to find details.

5. The format function, when applied on a string returns ___________
a) Error
b) int
c) bool
d) str
Answer: d
Clarification: Format function returns a string.

6. What will be the output of the “hello” +1+2+3?
a) hello123
b) hello
c) Error
d) hello6
Answer: c
Clarification: Cannot concatenate str and int objects.

7. What will be the output of the following Python code?

  1. >>>print("D", end = ' ')
  2. >>>print("C", end = ' ')
  3. >>>print("B", end = ' ')
  4. >>>print("A", end = ' ')

a) DCBA
b) A, B, C, D
c) D C B A
d) D, C, B, A will be displayed on four lines
Answer: c
Clarification: Execute in the shell.

8. What will be the output of the following Python statement?(python 3.xx)

  1. >>>print(format("Welcome", "10s"), end = '#')
  2. >>>print(format(111, "4d"), end = '#')
  3. >>>print(format(924.656, "3.2f"))

a)    Welcome# 111#924.66
b) Welcome#111#924.66
c) Welcome#111#.66
d) Welcome   # 111#924.66

Answer: d
Clarification: Execute in the shell to verify.

9. What will be displayed by print(ord(‘b’) – ord(‘a’))?
a) 0
b) 1
c) -1
d) 2
Answer: b
Clarification: ASCII value of b is one more than a. Hence the output of this code is 98-97, which is equal to 1.

10. Say s=”hello” what will be the return value of type(s)?
a) int
b) bool
c) str
d) String
Answer: c
Clarification: str is used to represent strings in python.

technical interview questions on Python,

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top