要在Python中打印信息,可以使用print()函数。print()函数用于输出文本或变量值。
以下是两个例子:
打印文本:print("Hello, World!")结果输出:
Hello, World!打印变量值:name = "John"print("My name is", name)结果输出:
My name is John在print()函数中,可以打印多个值,它们会以空格分隔。如果要打印不同类型的变量,可以使用字符串格式化或转换为字符串再打印。
例如,打印整数和浮点数:
age = 25weight = 68.5print("I am", age, "years old and my weight is", weight, "kilograms.")结果输出:
I am 25 years old and my weight is 68.5 kilograms. 
