Skip to content

Python concatenate string and variable | Example code

  • by

Simple + operator will use to concatenate strings and variables in Python. If contacting string and number variable then you have to convert the int into the string using str() function.

"In year " + str(intiger) + " I should learn more Python"

Example concatenate string and variable in Python

Simple example code.

Coordinate string and variable in Python

s = "The number is five "

print(s + str(5))

Output:

Python concatenate string and variable

How to concat strings in Python

Answer: Use + operator to concat strings in Python

a = "Hello"
b = "World"
c = a + " " + b
print(c)

Output: Hello World

Do comment if you have any doubts and suggestions on these concatenate examples.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *