Python: Can not understand why I am getting the error: Can not concatenate 'int' and 'str' object



This error is coming because the interpreter is replacing the %d with i and then trying to add 1 to a str, ie, adding a str and an int. In order to correct this, just surround the i+1 in parentheses. 

example

print("\

Num %d" % (i+1))
Updated on: 2020-03-12T12:31:58+05:30

101 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements