使用反斜杠(\)
print("这是第一行代码,\n这是第二行代码。"
使用括号
print(("这是第一行代码,"
"这是第二行代码。"
使用回车键
print("这是第一行代码,")
print("这是第二行代码。"
使用多行字符串
code = """
def my_function():
print("Hello world!")
"""
使用`input()`函数
code = ""
while True:
line = input()
if line == "":
break
code += line + "\n"
使用`re.compile()`
import re
code_lines = []
while True:
line = input()
if line == "":
break
code_lines.append(line)
使用第三方库(如`line-by-line`):
需要安装line-by-line库
from line_by_line import read_file
with open('code.py', 'r') as file:
for line in read_file(file):
print(line, end='')
请选择适合您需求的方法来输入第二行代码