Q. The format function, when applied on a string returns

  • (A) error
  • (B) int
  • (C) bool
  • (D) str
πŸ’¬ Discuss
βœ… Correct Answer: (D) str

Explanation: format function returns a string.

Q. >>>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
πŸ’¬ Discuss
βœ… Correct Answer: (C) d c b a

Explanation: execute in the shell.

Q. What will be displayed by print(ord(‘b’) – ord(‘a’))?

  • (A) 0
  • (B) 1
  • (C) -1
  • (D) 2
πŸ’¬ Discuss
βœ… Correct Answer: (B) 1

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

Q. Say s=”hello” what will be the return value of type(s)?

  • (A) int
  • (B) bool
  • (C) str
  • (D) string
πŸ’¬ Discuss
βœ… Correct Answer: (C) str

Explanation: str is used to represent strings in python.

Q. :.2%}'.format(1/3))

  • (A) 0.33
  • (B) 0.33%
  • (C) 33.33%
  • (D) 33%
πŸ’¬ Discuss
βœ… Correct Answer: (C) 33.33%

Explanation: the symbol % is used to represent the result of an expression as a percentage.

Jump to