开发者

Find string in another string using python

Lets say that you have an email address xxx@yyy.com and you want to create something like this in python:

email = 'mystuff@yyy.com'
try:
    if "@yyy.com":
    #do something

    if 开发者_运维技巧"@zzz.com":
    #do something else
except:
#do something

How would I do this?


email_addr = "foo@yyy.com"

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


email = "xxx@yyy.com"
if "@yyy.com" in email:
#do something

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜