free stats

Python Email Slicer Program

Last Update : 14 Sep, 2022 Python, Programming, Example

In this python project example, you will learn to create an Email Slicer program using Python. This program is very useful for separating the domain name and username of an email address.

For this, You need to write a program to retrieve the domain name and username of the email address.

For example, When considering the email address of [email protected]

The "admin" part of this email can be identified as the username.
The "uxpython.com" part of the email can be identified as the domain name.

Then, you can divide the input email address into two strings using "@" as the separator. 

Finally, you are able to just formatting to print the output.

 

The full code example of the Email Slicer program is as follows.

# Python Email Slicer Program
email_address = input("Enter Your Email Address: ").strip()

username = email_address[:email_address.index("@")]
domain_name = email_address[email_address.index("@")+1:]

format_username = (f"Your email username is '{username}'")
format_domain = (f"Your domain name is '{domain_name}'")
print(format_username)
print(format_domain)

This program produces the following result -:

Enter Your Email Address: [email protected]
Your email username is 'admin'
Your domain name is 'uxpython.com'

 

In the above code, First, take the input from the user. And,  if there are white spaces, remove them using the strip() function and store the email address in the variable of email. 

Then, find the index of the "@" symbol of the user input. And, the store user name of the email address into the username variable and store the domain name of the email address into the domain_name variable. Finally, print the output on the console.

Also, you can make your own program using this code by adding many more features. 

 

You found this tutorial / article valuable? Need to show your appreciation? Here are some options:

01. Spread the word! Use following buttons to share this tutorial / article link on your favorite social media sites.

02. Follow us on Twitter, GitHub ,and Facebook.