Difference between + and , Python Print
Last Updated :
13 Oct, 2023
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.
'+' 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)
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))
',' in Python Print Statement
Python ',' operator is used to separate multiple arguments passed to the print() function. When used with the print() function, it can be used to print multiple values or variables on separate lines. It automatically adds a single white space between the arguments.
Syntax of ',' in Python Print:
print(arg1, arg2, arg3, ...)
In this example, we can see that we did not provide any white space in the string, but the ',' operator automatically added a single white space between the values.
Python
name = "Raj"
age = 27
print("Name:",name)
print("Age:",age)
Output('Name:', 'Raj')
('Age:', 27)
Difference Between + and , in Python Print
Let's see the difference between + and , in Python print.
|
It is used to concatenate or add the values
| It separates multiple values or variables passed to the function
|
Example: print("Hello" + " " + "world") would result in "Hello world"
| Example: print("Hello", "world") would result in "Hello world"
|
It does not add white space between the values
| It automatically adds a single white space between the values.
|
It returns the new value that is the result of the concatenation or addition operation
| Does not return the value, but prints the values passed to the function to the console
|
It is used for explicit string concatenation i.e, we need to convert non-string data types to strings using functions like str() if they are not already strings.
| Explicit string concatenation is not necessary. We can print a mix of data types without explicit type conversion.
|
Similar Reads
Python - Difference between := and == In this article, we will be discussing the major differences between Walrus(:=) and the Comparison operator (==):= in PythonThe := operator in Python, also known as the walrus operator or assignment expression, was introduced in Python 3.8. It enables assignment and evaluation to happen simultaneous
2 min read
Difference between return and print in Python In Python, we may use the print statements to display the final output of a code on the console, whereas the return statement returns a final value of a function execution which may be used further in the code. In this article, we will learn about Python return and print statements. Return Statement
2 min read
Difference Between '+' and 'append' in Python + Operator creates a new sequence by concatenating two existing sequences and .append() method (available for lists) modifies the existing list in place by adding one item at the end. In this article we are going to compare '+' operator and append in Python.+ Operator in Python+ operator is typicall
3 min read
Difference between 'and' and '&' in Python and is a Logical AND that returns True if both the operands are true whereas '&' is a bitwise operator in Python that acts on bits and performs bit-by-bit operations.Note: When an integer value is 0, it is considered as False otherwise True when used logically.and in PythonThe 'and' keyword in P
6 min read
Difference between end and sep in Python In this article we will discuss the difference between The end and sep are two parameters in Python's built-in print() function that will help to control how the output is formatted. end in PythonThe end is a parameter in Python's built-in print() function that controls what character(s) are printed
2 min read
Difference Between x = x + y and x += y in Python We often use x += y instead of x = x + y. So, are they same or different? Let's Find it here. Example 1: Python3 x = [1, 2] another_x = x y = [3] x += y print(x) print(another_x) Output: [1, 2, 3] [1, 2, 3] Example 2: Python3 x = [1, 2] another_x = x y = [3] x = x + y print(x) print(another_x) Outpu
2 min read
Difference between %s and %d in Python string In this article, we will see the difference between %s and %d in Python. Here, we start with the proper explanation of one at a time, then both, and at last compare these. What does %s do in Python? The % symbol is used in Python with a large variety of data types and configurations. It is used as a
3 min read
Difference between != and is not operator in Python In this article, we are going to see != (Not equal) operators. In Python != is defined as not equal to operator. It returns True if operands on either side are not equal to each other, and returns False if they are equal. Whereas is not operator checks whether id() of two objects is same or not. If
3 min read
Difference between append() and extend() in Python extend() and append() are two Python list methods used to add elements to a list but they behave quite differently. The append() adds a single item or any object, while extend() adds each element of an iterable to the list. In this article, weâll explore the differences between append() and extend()
2 min read
Difference between for loop and while loop in Python In this article, we will learn about the difference between for loop and a while loop in Python. In Python, there are two types of loops available which are 'for loop' and 'while loop'. The loop is a set of statements that are used to execute a set of statements more than one time. For example, if w
4 min read