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: 12-Mar-2020

70 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements