小编Hua*_*uan的帖子

对嵌套打印用法中的打印顺序感到困惑

在嵌套打印函数时,Python 3的默认打印序列存在一些问题,可以将其简化为以下示例:

>>> def print2():
...     print('print2')
... 
>>> print('print1', print2())
print2
print1 None
Run Code Online (Sandbox Code Playgroud)

但是在Python 2中使用等效项:

>>> def print2():
...     print 'print2'
... 
>>> print 'print1', print2()
print1 print2
None
Run Code Online (Sandbox Code Playgroud)

为什么打印顺序颠倒了?以及如何在Python 3中产生自然顺序(与Python 2中相同),而不是逆转

python python-2.7 python-3.x

3
推荐指数
1
解决办法
52
查看次数

标签 统计

python ×1

python-2.7 ×1

python-3.x ×1