To take into account some other answers, you have the following options:
If you know that the string will have a “@” character, you can simply do the following:
>>> domain = a.split('@')[1]
If it is likely that you do not have the '@' character, then one of the following is suggested:
>>> domain = a.partition('@')[2]
or
try: domain = a.split('@')[1] except IndexError: print "Oops! No @ symbols exist!"
josh-fuggle
source share