多行语句

Python 通常是一行写完一条语句,但如果语句很长,我们可以使用反斜杠(\)来实现多行语句,例如:

total = item_one + \
        item_two + \
        item_three

在 [], {}, 或 () 中的多行语句,不需要使用反斜杠(\),例如:

total = ['item_one', 'item_two', 'item_three',
        'item_four', 'item_five']

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-11
  • 2022-12-23
  • 2021-08-11
  • 2021-08-28
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案