Problem with python
Rob Cliffe
rob.cliffe at btinternet.com
Sat Sep 4 16:07:11 EDT 2021
Well, up to a point.
In Python 2 the output from
print 1, 2
is '1 2'
In Python 3 if you add brackets:
print(1, 2)
the output is the same.
But if you transplant that syntax back into Python 2, the output from
print(1, 2)
is '(1, 2)'. The brackets have turned two separate items into a single
tuple.
If you want Python 2- and 3-compatibility you must find a work-around
such as
print('%d %d' % (1,2))
print('%s %s' % (1,2))
print(str(1) + ' ' + str(2))
Similarly
'print' in Python 2 outputs a blank line.
'print()' in Python 3 outputs a blank line. In python 2 it prints
a line containing a blank tuple: '()'.
A 2/3-compatible way of outputting a blank line is
print('')
Best wishes
Rob Cliffe
On 04/09/2021 20:50, Peter J. Holzer wrote:
> On 2021-09-04 14:29:47 -0500, Igor Korot wrote:
>> Will this syntax work in python 2?
> Yes. It's just a redundant pair of parentheses.
>
> hp
>
>
More information about the Python-list
mailing list