【问题标题】:Split string when ";" appears [duplicate]“;”时拆分字符串出现[重复]
【发布时间】:2018-02-09 12:35:48
【问题描述】:

每次出现; 时我都需要拆分字符串。

words = "LightOn;LightOff;LightStatus;LightClientHello;"

输出应该是这样的:

LightOn
LightOff
LightStatus
LightClientHello

简单地说,每次在字符串中找到;,它都必须拆分它。

感谢您的帮助

【问题讨论】:

  • 解决方案非常简单 - 在 Python 文档中查看 .split()
  • words.split(';')?
  • words.split 没有给我我需要的输出。
  • 好的,已经知道了。

标签: python string


【解决方案1】:
res = words.split(";")

有关拆分的更多信息,请参阅this link

【讨论】:

    猜你喜欢
    • 2023-01-12
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    • 2017-04-09
    • 2014-10-14
    • 2010-11-03
    • 1970-01-01
    相关资源
    最近更新 更多