In this article, you will see how to check if a string is an email in Python. An email string is a string that contains an email address with the @ sign. We can use count() along with this
strip() method to check if a string contains an @ sign.
Step 1: Create a string
str = "firstname.lastname@example.org" print("str = ", str) print("str type = ", type(str))
Step 2: Check if string is a email
if str.strip().count("@") == 1: print("Email") else: print("Not Email")
str = email@example.com str type = <class 'str'> Email
Free resources to learn advanced skills: AiHints and CodeAllow