1. 使用反斜杠(\):
total_sum = 100 + 200 + 300 + \
400 + 500 + 600
print(total_sum) 输出:2100
2. 使用括号(()):
fruits = [
'apple',
'banana',
'cherry',
'date'
]
3. 使用三引号(''' 或 """):
message = """亲爱的Python学习者:
欢迎来到代码的世界!"""
4. 使用加号(+)连接字符串:
line1 = "这是第一行。"
line2 = "这是第二行。"
text = line1 + " " + line2
print(text) 输出:这是第一行。 这是第二行。
5. 使用分号(;)分隔语句,但这通常不推荐用于换行,因为分号用于结束语句,而不是换行。
请根据您的需要选择合适的换行方法