top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

A Simple Email Splitter

Updated: Sep 18, 2021



In this article, You will learn two ways to split an email address into username and domain . Before we go into the details of doing this let's first define the username and domain. The username appears to the left of the @ symbol, while the domain appears to the right. saf@gmail.com, for example, has the username 'saf', and gmail.com is the domain name.


Method 1: using index() + slicing


This method takes advantage of the fact that the @ symbol naturally separates the username from the domain. The python index () method is used to return the index of the @ symbol and then simple string slicing can be used to split the email into two parts as follows:


# Email splitter for separating the username and domain
# Method 1 

# intializing the email 
email =input("Enter Your Email address: ").strip()

# separating the username and the domain name using slicing: 
user= email[0:email.index('@')]
domain=email[email.index('@')+1:]

# printing the result :
print('the username is:' +str(user) )
print('the domain is:'+str (domain) )

Result :


 

Method 2: split method


The string split method is used to split the email on @, which results in a list. The first element in the obtained list is the username, while the second element is the domain.


#Email splitter for separating the username and domain name
# Method 2
# intializing the email 
email =input("Enter Your Email address: ").strip()


# separating the username and the domain name using split method : 
user=email.split('@')[0]
domain=email.split('@')[1]

# printing the result :
print('the username is:' +str(user) )
print('the domain is:'+str (domain) )

Result :



 

The source code is available on Github.




 
 
 

Comments


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page