‘+’ in Python Print Statement

The ‘+’ operator is an arithmetic operator which is also used to concatenate two strings. It does not add white space in between strings, you have to provide it manually if you want to separate two strings. The print() function, can be used to combine multiple strings and print them to the console as a single line.

Syntax of ‘+’ Operator in Python Print:

print(string 1 + string2)

Example 1:

In this example, we can see that we did not provide any white space in the string. So when we try to print them using the + operator, string 1 and string 2 concatenate with each other.

Python




str1 = "Hello"
str2 = "World"
print(str1 + str2)


Output

HelloWorld





Example 2:

In this example, we can see that we provided a space between the strings – “Name” and “Age”. So when we printed them using the + operator, the white space was printed in the output as well. Also, it is used to concatenate strings, so we convert the age to string using the str() function.

Python




name = "Raj"
age = 26
print("Name: " + name + ", Age: " + str(age))


Output

Name: Raj, Age: 26





Difference between + and , Python Print

In this article, we will learn about the difference between + and, in Python print, The print() function in Python is used to print some messages as the output on the screen. We can print a single element or even multiple elements on the screen. Python provides two ways to print multiple elements as the output using the ‘+ operator’ and ‘, operator’. Let us see how they work with the print statement.

Similar Reads

‘+’ in Python Print Statement

The ‘+’ operator is an arithmetic operator which is also used to concatenate two strings. It does not add white space in between strings, you have to provide it manually if you want to separate two strings. The print() function, can be used to combine multiple strings and print them to the console as a single line....

‘,’ in Python Print Statement

...

Contact Us