在Python中可以使用print函数来输出信息。如果要输出字符串,可以将字符串直接作为参数传递给print函数,例如:
print("hello, world")
如果要输出变量,可以使用格式化字符串,将变量的值插入到字符串中。例如:
name = "Bob"
age = 24
print("My name is %s, and I am %d years old." % (name, age))
另外,Python还提供了多种格式化字符串的方式,如使用.format()方法或者使用f-strings。例如:
print("My name is {}, and I am {} years old.".format(name, age))
# 或者
print(f"My name is {name}, and I am {age} years old.")
如果想在同一行输出多个信息,可以使用print函数的end参数。例如:
print("hello,", end="")
print("world")
输出结果为:
hello,world