在Python中,换行可以通过以下几种方式实现:
1. 使用行尾换行符 `\n`:
print("Hello,\nWorld!")
输出:
Hello,
World!
2. 使用括号进行隐式换行:
fruits = ['apple', 'banana', 'cherry', 'date']
message = """亲爱的Python学习者:
欢迎来到代码的世界!"""
4. 使用反斜杠 `\` 链接多行代码:
total_sum = 100 + 200 + 300 + 400 + 500 + 600
print(total_sum)
输出:
2100
5. 使用圆括号 `()` 自动换行:
result = some_function(
argument1,
argument2,
argument3
)