Python 的 按行分割字符串

等级 253 次按键

这使用splitlines()方法在行边界处分割字符串,返回行列表。

Python 代码

# 使用\n创建多行字符串
1text = "line1\nline2\nline3"
# splitlines()在每个换行符处分割
# 返回单独行的列表
2print(text.splitlines())

运行结果

['line1', 'line2', 'line3']
用这段代码练习打字

可以用这段代码练习打字。成绩不会计入排行榜。

这段代码中的符号

这段 Python 代码中需要输入的符号及其出现次数。

  • "× 2
  • (× 2
  • )× 2
  • \× 2
  • .× 1
  • =× 1

Python 等级 2 的更多代码示例

← 返回 Python 打字练习