KnowledgeBoat Logo
|

Informatics Practices

What will be the correct output of the following code:

a, b = '30', '5'
c = a+b
print(c)
  1. 19
  2. 305
  3. ValueError
  4. TypeError

Python Funda

3 Likes

Answer

305

Reason — In the above code, a and b are strings as they are enclosed in quotes. When using the + operator with strings, it performs concatenation rather than arithmetic addition. Therefore, a + b results in the concatenation of '30' and '5', producing '305'.

Answered By

3 Likes


Related Questions