KnowledgeBoat Logo

Computer Science

Which line of code produces an error ?

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

Python String Manipulation

1 Like

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.

Answered By

3 Likes


Related Questions