Extract Alphabetic Characters from String in Python

✅ *Python Scenario-Based Interview Question* 🧠 You have a string: ``` text = "DataScience2026" ``` *Question:* Extract only the alphabetic characters from the string (remove numbers). *Expected Output:* ``` DataScience ``` *Python Code:* ``` letters_only = ''.join([char for char in text if char.isalpha()]) print(letters_only) ``` *Explanation:* – `char.isalpha()` checks if the character is a letter – List comprehension filters only letters, then joins them back to a string

To view or add a comment, sign in

Explore content categories