When I am using sep argument in the Python 2.7.3, it is showing error
for example:-
>>>print ("Hello","World",sep ="**")
File "<stdin>", line 1
print ("Hello","World",sep ="**")
^
SyntaxError: invalid syntax
You need to type this line first:
from __future__ import print_function
To make print
a function, and allow passing arguments like that.
In Python 2.x, unlike in Python 3.x, print
is not a function, but a statement described here. Basically it means that print
is treated as a keyword (like for
) and is not as powerful as the print
function that you know from Python 3.x. In particular, it does not support the sep
keyword argument.
You can make print
behave similarly to Python 3.x by using the following import:
from __future__ import print_function
If you prefer no to use this import, you can achieve the effect you wanted with:
print "**".join(["Hellow", "World"])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With