Check if a String is an Email in Python

  • Post category:String

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 = ""
print("str = ", str)
print("str type = ", type(str))

Step 2: Check if string is a email

if str.strip().count("@") == 1:
    print("Not Email")


str =
str type =  <class 'str'>

Free resources to learn advanced skills: AiHints and CodeAllow