๐Ÿ“ข Too many exams? Donโ€™t know which one suits you best? Book Your Free Expert ๐Ÿ‘‰ call Now!

  • google app store apple app store
  • โœ–

      Question

      Complete the Python code to check if a string email

      matches a simple email pattern (e.g., [email protected]). import re def is_valid_email(email): ย  ย  pattern = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" ย  ย  _________ # Line to complete
      A return re.match(pattern, email) Correct Answer Incorrect Answer
      B return re.search(pattern, email) Correct Answer Incorrect Answer
      C return re.fullmatch(pattern, email) Correct Answer Incorrect Answer
      D return re.findall(pattern, email) Correct Answer Incorrect Answer
      E return re.compile(pattern).match(email) Correct Answer Incorrect Answer

      Solution

      Correct Answer: C (re.fullmatch ensures the *entire* string matches the pattern, which is typically desired for validation like email. re.match only checks from the beginning, and re.search checks anywhere in the string.)

      Practice Next
      ask-question