在Python中打印单个和多个变量
在Python 3.X中,打印语句写为 一个print()函数。下面是Python 3.X 中的代码,显示了在Python中打印值的过程。
示例 1:打印单个值
Python3
# Equivalent codes in Python 3.0
# (Produces same output)
# Code 1:
print(1)
# Code 2 :
print((1))
Python3
# Code 1:
print(1, 2)
# Code 2:
print((1, 2))
# Code 3:
# printing on the same line
# for printing on the same line use
# end parameters of the print function
# end takes the values which is printing
# at the end of the output.
print(1, end=" ")
print(2)
输出:
1
1
示例 2:打印多个值
Python3
# Code 1:
print(1, 2)
# Code 2:
print((1, 2))
# Code 3:
# printing on the same line
# for printing on the same line use
# end parameters of the print function
# end takes the values which is printing
# at the end of the output.
print(1, end=" ")
print(2)
输出:
1 2
(1, 2)
1 2