在Python shell中换行,您可以使用以下方法:
1. 使用反斜杠(\)进行换行:
a = 1
b = 2
c = a + \
b
print(c)
2. 在冒号(:)后按回车键进行换行:
def my_function():
print("This is a new line")
3. 使用三引号(单引号或双引号都可以)来创建多行字符串,这样可以在字符串内部换行:
my_string = """This is a new line
inside a string"""
print(my_string)
4. 将代码写入.py文件中,然后执行该文件:
my_script.py
print("This is a new line")
5. 使用括号、方括号或大括号中的表达式,可以在不使用反斜杠的情况下换行:
python my_script.py
请选择适合您需求的方法进行换行