How to make Email slicer using python

So here we will learn how to make email slicer using python

So the first question arises: what is Email – Slicer?

Email slicer is nothing but we just pass the email id and it will return the user_name and domain_name

So now let see the code part

email_address = input(“enter your email address”).strip()

username = email_adress[:email_adress.index(‘@’)]

domain = email_adress[email_adress.index(‘@’) + 1:]

print(f”your username {username} and domain name {domain}”)

Here in the first line we have taken email_address variable and taken input from user and also used strip function for removing unwanted space, now in second line we have taken username variable where we are performing slicing here it will check the index where “@” will come until that it will store the string in username as starting index is 0  because we have not defined anything .

In the next line we have defined starting index after “@” to the last.

At the end we have printed the result.

Here we have used f litrel which will help to provide values to username and domain in run time.

I hope you understand the code

We can also use partition function as a alternative method

So here the code if we are using partition function

email_address = input(“enter your email address”).strip()

new = email_address.partition(“@”)

print(f”user name {new[0] } and {new[-1]}”)

 Here in new variable we have do partition so it will give us result like 

(“rajatupd”,”@” “ so at the end we have print this variable


So I hope you liked both the method let me know which is most effective you think

Keep learning!!

Leave a Reply

Your email address will not be published. Required fields are marked *