In this program, we will take email as string input and extract the name from the email address.
Steps to solve the program
- Take an email id of a student as string input.
- Find the index number of “@” using index().
- Create an empty string.
- Add characters from the email id to the empty string using for loop up to the index of “@”.
- Add only alphabets not numbers use isalpha() for this purpose.
- Print the output.
#Input string
str1 = "student1@gmail.com"
index = str1.index("@")
str2 = ""
for char in str1[:index]:
if char.isalpha():
str2 += char
#Printing output
print(str2)
Output :
student