在Python 2中,换行可以通过以下几种方式实现:
1. 使用反斜杠(\)进行换行:
print("Hello,\nworld!")
2. 使用括号进行隐式换行:
total = 1 + 2 + 3 + \
4 + 5 + 6 + \
7 + 8 + 9
print(total)
message = """亲爱的Python学习者:
欢迎来到代码的世界!"""
以上方法都可以在Python 2中使用,以增强代码的可读性。需要注意的是,在Python 2中,三引号创建的多行字符串不会保留原有的换行和缩进。