Engineering Questions with Answers - Multiple Choice Questions

Python MCQs

1 - Question

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

  1. >>>chr(ord('A'))

a) A
b) B
c) a
d) Error

View Answer

Answer: a
Explanation: Execute in shell to verify.




2 - Question

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

View Answer

Answer: c
Explanation: Execute in the shell to verify.




3 - Question

3. Which of the following statement prints hello\example\test.txt?
a) print(“hello\example\test.txt”)
b) print(“hello\\example\\test.txt”)
c) print(“hello\”example\”test.txt”)
d) print(“hello”\example”\test.txt”)

View Answer

Answer: b
Explanation: \is used to indicate that the next \ is not an escape sequence.




4 - Question

4. Suppose s is “\t\tWorld\n”, what is s.strip()?
a) \t\tWorld\n
b) \t\tWorld\n
c) \t\tWORLD\n
d) World

View Answer

Answer: d
Explanation: Execute help(string.strip) to find details.




5 - Question

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

View Answer

Answer: d
Explanation: Format function returns a string.




6 - Question

6. What will be the output of the “hello” +1+2+3?
a) hello123
b) hello
c) Error
d) hello6

View Answer

Answer: c
Explanation: Cannot concatenate str and int objects.




7 - Question

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

View Answer

Answer: c
Explanation: Execute in the shell.




8 - Question

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

View Answer

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




9 - Question

9. What will be displayed by print(ord(‘b’) – ord(‘a’))?
a) 0
b) 1
c) -1
d) 2

View Answer

Answer: b
Explanation: ASCII value of b is one more than a. Hence the output of this code is 98-97, which is equal to 1.




10 - Question

10. Say s=”hello” what will be the return value of type(s)?
a) int
b) bool
c) str
d) String

View Answer

Answer: c
Explanation: str is used to represent strings in python.

Get weekly updates about new MCQs and other posts by joining 18000+ community of active learners