使用python中的单个打印在单独的行中打印多个变量

Fak*_*een 0 python printing

例如,我有两个变量int1 = 5,int2 = 3如何只使用一个打印而不用类型转换为str,在单独的行中打印两个整数.(如在C++以下:print)

ins*_*get 7

在python3中:

print(string1, string2, sep='\n')
Run Code Online (Sandbox Code Playgroud)

在python2中:

print string1 + '\n' + string2
Run Code Online (Sandbox Code Playgroud)

...或者from __future__ import print_function使用python3的打印

自从我的第一个回答以来,OP已经使用变量类型更改编辑了问题.更新已更新问题的答案:

如果你有一些整数,即int1int2:

Python 3:

print(int1, int2, sep='\n')
Run Code Online (Sandbox Code Playgroud)

Python 2:

print str(int1) + '\n' + str(int2)
Run Code Online (Sandbox Code Playgroud)

要么

from __future__ import print_function

print(int1, int2, sep='\n')
Run Code Online (Sandbox Code Playgroud)

要么

print '\n'.join([str(i) for i in [int1, int2]])
Run Code Online (Sandbox Code Playgroud)