温馨提示×

python print怎么输出变量

小亿
212
2024-01-17 08:10:37
栏目: 编程语言
Python开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

要在Python中打印变量,您可以使用print语句或print函数。下面是两种方法的示例:

  1. 使用print语句:
variable = 'Hello, World!'
print variable
  1. 使用print函数:
variable = 'Hello, World!'
print(variable)

请注意,在Python 2.x中,print语句不需要括号,但在Python 3.x中,print函数需要括号。使用哪种方法取决于您使用的Python版本。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:python print如何输出变量

0