pythonslice

Slicing in Python, one part of string


I have one challenge to complete!

I have one form that takes the email typed, like this: (Always in this format) example: bianca.mary@john.com

I need to get the first part (bianca) before '.' and put this in one label and in another label, put the second part (mary).

Could you help me?


Solution

  • dotPoint = text.index(".")
    atPoint = text.index("@")
    firstPart = text[0:dotPoint]
    secondPart = text[dotPoint+1:atPoint]
    print firstPart
    print secondPart
    

    This will output

    bianca
    mary
    

    There you go. On Python 2.7 :)