Linux 拨号vps windows公众号手机端

python如何打印

lewis 8年前 (2017-04-02) 阅读数 7 #程序编程
文章标签 python

要在Python中打印信息,可以使用print()函数。print()函数用于输出文本或变量值。

以下是两个例子:

  1. 打印文本:
print("Hello, World!")

结果输出:

Hello, World!
  1. 打印变量值:
name = "John"
print("My name is", name)

结果输出:

My name is John

在print()函数中,可以打印多个值,它们会以空格分隔。如果要打印不同类型的变量,可以使用字符串格式化或转换为字符串再打印。

例如,打印整数和浮点数:

age = 25
weight = 68.5
print("I am", age, "years old and my weight is", weight, "kilograms.")

结果输出:

I am 25 years old and my weight is 68.5 kilograms.
版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门