Split a string by a delimiter in python

前端 未结 3 1383
名媛妹妹
名媛妹妹 2020-11-22 06:58

How to split this string where __ is the delimiter

MATCHES__STRING

To get an output of [\'MATCHES\', \'STRING\']?

3条回答
  •  时光取名叫无心
    2020-11-22 07:50

    When you have two or more (in the example below there're three) elements in the string, then you can use comma to separate these items:

    date, time, event_name = ev.get_text(separator='@').split("@")
    

    After this line of code, the three variables will have values from three parts of the variable ev

    So, if the variable ev contains this string and we apply separator '@':

    Sa., 23. März@19:00@Klavier + Orchester: SPEZIAL

    Then, after split operation the variable

    • date will have value "Sa., 23. März"
    • time will have value "19:00"
    • event_name will have value "Klavier + Orchester: SPEZIAL"

提交回复
热议问题