Email Slicer in Python

Lewis Summers
1 min readMay 31, 2021

I am using PyCharm and python 3.9 to make a email slicer.

Email slicers are easy, easy and can be useful if implemented into bigger projects. Basically, an email slicer returns the username and domain name of an email address.

First, we need to get an email address to slice so we use the input function like this:

email = input("Email Address: ").strip()

then we need to find where in the email the @ is. The index function returns the position of the first string, so if I had a list the was [6, 2, 7, 6] and I ran list.index(‘6’) then it would return 0. This is how you find the @ in an email address.

pos = email.index('@')

From there you can say okay everything after the @ is the domain name and everything before is the username. You would do that like this:

username = email[:pos]
domainName = email[pos+1:]

Then just print the variables username and domainName and there you go, you made an email slicer.

Full code.

email = input("Email Address: ").strip()

pos = email.index('@')

username = email[:pos]
domainName = email[pos+1:]
print(" ")
print("Email address:", email)
print("Username:", username)
print("Domain name:", domainName)

--

--