print

したがって,print文は次のように使う.

- 必ず引数をカッコの中に入れる

- python 2.Xでも美しく表示させるには,書式付きで書く.

python3.xではprintは関数なので,引数はすべて()の中に入れなくてはならない.python 2.xでは入れなくてもよかった.そこで,どちらでも動くように書くために,python 3.xの書法で書くこと.たとえば,

x=1

print('x=',x)

はpython 3.x, 2.xのどちらでも動く.ただし表示は

x= 1 # python 3.6

('x=', 1) # python 2.7

とpython 3.xのほうが美しい.書式付きで

print('x=%d'%x)

と書けば,python 2.7, 3.6の両方で

x=1

となる.

For python 3.X, print is a function, and all arguments should be included within (). This is not necessary for python 2.X. So in order to make your scripts working on both, you should use python 3.x convention. For example, the following two lines work both versions.

x=1

print('x=',x)

But results in display are somewhat different,

x= 1 # python 3.6

('x=', 1) # python 2.7

Apparently python 3.6 gives better look.

To give a good look for both versions, you should use format. So, if you write

print('x=%d'%x)

then, results on both python 2.7 and 3.6 are identical as

x=1.

So you should keep two rules for print.

- Arguments should be in ()

- If you want to get a good looking results even for python 2.x, you will use format.