Use comma “,” to separate strings and variables while printing int and string in the same line in Python or convert the int to string.
There are many ways to print int and string in one line, some methods are:-
Method 1
print('String', int_vlaue)
Method 2
When adding strings, they concatenate.
print('string' + str(a))
Method 3
print('String %d %s' % (a, b))
Method 4
the format (Python 2.6 and newer) method of strings is probably the standard way:
print('String {} {}'.format(a, b))
Example how to print variable and string on the same line in Python
Simple example code.
s = "Hello"
i = 10
print(s, i)
print(s + str(i))
print("String %d %s" % (10, 20))
print("String {}".format(i))
Output:
Do comment if you have any doubts and suggestions on this Python int string topic
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.