0

Lets say that you have an email address [email protected] and you want to create something like this in python:

email = '[email protected]'
try:
    if "@yyy.com":
    #do something

    if "@zzz.com":
    #do something else
except:
#do something

How would I do this?

2 Answers 2

7
email_addr = "[email protected]"

if email_addr.endswith("@yyy.com"):
    # do something
elif email_addr.endswith("@zzz.com"):
    # do something else

# or...

if "@yyy.com" in email_addr:
    # do something
elif "@zzz.com" in email_addr:
    # do something else
Sign up to request clarification or add additional context in comments.

2 Comments

for some reason this isn't working. is there something that I'm missing? what library does this use?
It doesn't use any library; these are all part of the standard Python distribution.
0
email = "[email protected]"
if "@yyy.com" in email:
#do something

if "@zzz.com" in email:
#do something else

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.