Python 2.7.3: Sep argument shows error

When I use the sep argument in Python 2.7.3, it shows an error

eg: -

      >>>print ("Hello","World",sep ="**")
           File "<stdin>", line 1
           print ("Hello","World",sep ="**")
                           ^
          SyntaxError: invalid syntax
+4
source share
2 answers

In Python 2.x, unlike Python 3.x, printit is not a function, but the instruction described here . This basically means that it is printconsidered as a keyword (for example for) and not as strong as a function printthat you know from Python 3.x. In particular, it does not support the keyword argument sep.

Using:

from __future__ import print_function

You can make it printbehave like a function printin Python 3.x.

, print_function __future__ :

print "*".join(["Hellow", "World"])
+9

:

from __future__ import print_function

print .

0

All Articles