Search code examples
pythonemailgetat-command

How can I get the characters that come after the @ on email value with python?


I want to know what comes especificaly after the "@" on an email value that is in an input with python, what are ways to do it?

Examples: email: input("Write your email: ")

User input: Write you email: [email protected]

[email protected] result: hotmail.com

[email protected] result: gmail.com

I have no idea on how I can do it, but I would try manging strings and using len()


Solution

  • You can do this way:

    email = '[email protected]'
    
    #Get the index of '@' with find method and add 1 to it
    idx = email.find('@') + 1
    
    #Get the character with email[idx]
    required_character = email[idx]
    
    print(required_character) #output : 'h'
    
    #to get the domain name after the symbol @
    domain = email[idx:]
    print(domain) #output : hotmail.com