Python Split String

前端 未结 7 1996
名媛妹妹
名媛妹妹 2020-12-06 17:42

Lets Say we have Zaptoit:685158:zaptoit@hotmail.com

How do you split so it only be left 685158:zaptoit@hotmail.com

相关标签:
7条回答
  • 2020-12-06 18:12

    As of Python 2.5 there is an even more direct solution. It degrades nicely if the separator is not found:

    >>> s = 'Zaptoit:685158:zaptoit@hotmail.com'
    >>> s.partition(':')
    ('Zaptoit', ':', '685158:zaptoit@hotmail.com')
    
    >>> s.partition(':')[2]
    '685158:zaptoit@hotmail.com'
    
    >>> s.partition(';')
    ('Zaptoit:685158:zaptoit@hotmail.com', '', '')
    
    0 讨论(0)
提交回复
热议问题