print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
#objects - 要打印的对象
#sep - 分隔符
#end - 结束符
#file - 输出目标
#flush - 是否立即刷新缓冲区
2.打印多个值
print("Hello", "World", 123, 4.56)
# 输出:Hello World 123 4.56
3.指定分割符(sep)(默认空格)
print("2023", "12", "25", sep="-")
# 输出:2023-12-25
4.指定结束符(end)(默认换行"\n")
print("Hello", end="")
print("World", end="!")
# 输出:HelloWorld!
5.输出到文件
with open("output.txt", "w") as f:
print("Hello File", file=f)
6.格式化输出(f"{}")
name = "Alice"
age = 25
#python3.6+
print(f"My name is {name} and I'm {age} years old")
#format
print("My name is {} and I'm {} years old".format(name, age))
7.打印列表、字典等
#打印列表
numbers = [1, 2, 3, 4, 5]
print(numbers) # [1, 2, 3, 4, 5]
#解包列表
print(*numbers) # 1 2 3 4 5
print(*numbers, sep=", ") # 1, 2, 3, 4, 5
#打印字典
person = {"name": "Bob", "age": 30}
print(person) # {'name': 'Bob', 'age': 30}
8.多行打印
print("""第一行
第二行
第三行""")