Python concatenate string and int | Example code

Use the str() function to concatenate string and int in Python. If you try to concatenate string and int using + operator, the program will throw a runtime error.

Example concatenate string and int in Python

Simple example code using str() function. You have to pass the int value into an str() function to convert it.

After converting int into a string you can use the + operator.

s = "Hello"
n = 100

print("Hello" + str(n))


Python concatenate string and int

Other methods

Using % Operator, format() function or f-strings can use too for concatenation of string and int.

s = "Hello"
n = 100

# % Operator
print("%s%s" % (s, n))

# format() function
print("{}{}".format(s, n))

# f-strings



Do comment if you have any doubts and suggestions on this Python concatenate topic.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.