Python Split String

前端 未结 7 1995
名媛妹妹
名媛妹妹 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 17:54

    Another method, without using split:

    s = 'Zaptoit:685158:zaptoit@hotmail.com'
    s[s.find(':')+1:]
    

    Ex:

    >>> s = 'Zaptoit:685158:zaptoit@hotmail.com'
    >>> s[s.find(':')+1:]
    '685158:zaptoit@hotmail.com'
    
    0 讨论(0)
  • 2020-12-06 17:59

    Following splits the string, ignores first element and rejoins the rest:

    ":".join(x.split(":")[1:])
    

    Output:

    '685158:zaptoit@hotmail.com'
    
    0 讨论(0)
  • 2020-12-06 17:59

    Use the method str.split() with the value of maxsplit argument as 1.

    mailID = 'Zaptoit:685158:zaptoit@hotmail.com' 
    mailID.split(':', 1)[1]
    

    Hope it helped.

    0 讨论(0)
  • 2020-12-06 18:01
    >>> s = 'Zaptoit:685158:zaptoit@hotmail.com'
    >>> s.split( ':', 1 )[1]
    '685158:zaptoit@hotmail.com'
    
    0 讨论(0)
  • 2020-12-06 18:04

    Another solution:

    s = 'Zaptoit:685158:zaptoit@hotmail.com'
    s.split(':', 1)[1]
    
    0 讨论(0)
  • 2020-12-06 18:05
    s = re.sub('^.*?:', '', s)
    
    0 讨论(0)
提交回复
热议问题