Extract a Domain from an Email Address
Beginner · Write the code · from Python Strings: Create, Access, Slice, and Manipulate Text
From the lesson: Python Strings: Create, Access, Slice, and Manipulate Text
Think about your phone. Almost everything you see on the screen is text: names in your contacts, messages from friends, search results, notifications. Behind the scenes, all of that text is handled by strings.
Read the lessonYou are given an email address stored in email. Extract just the domain name (the part after the @ symbol) and print it.
Expected output:
gmail.comUse the .find() method to locate the @ symbol, then use slicing to extract everything after it.
email = "alice@gmail.com"
# Find the position of the @ symbol
# Slice the string to get the domain
# Print the domain
More Strings exercises
- Build a Greeting with ConcatenationBeginner
- Get the First and Last CharacterBeginner
- Reverse a StringBeginner
- Predict the Slice OutputBeginner
- Fix the Bug: Mutating a StringBeginner
- Check If a Word Is in a SentenceBeginner
All Python exercises · 50 practice problems · Python Fundamentals quiz