CBSE Class 12 Computer Science Question 34 of 105

Python Revision Tour II — Question 13

Back to all questions
13
Question

Question 13

Which line of code produces an error ?

  1. "one" + 'two'
  2. 1 + 2
  3. "one" + "2"
  4. '1' + 2
Answer

'1' + 2

Reason — The + operator has to have both operands of the same type either of number type (for addition) or of string type (for concatenation). It cannot work with one operand as string and one as a number.