‘,’ 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) |
('Name:', 'Raj') ('Age:', 27)
Difference Between + and , in Python Print
Let’s see the difference between + and , in Python print.
‘ + ‘ in Python Print |
‘ , ‘ 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. |
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.
Contact Us