isalpha(): Check for Alphabet Characters

my_str.isalpha())
Returns True if all chars are alphabets in a string, Otherwise False is returned.
my_str='plus2net'
print(my_str.isalpha())      # Output is False

my_str='Welcome'
print(my_str.isalpha())      # Output is True

my_str='#1234'
print(my_str.isalpha())      # Output is False

my_str='12.34'
print(my_str.isalpha())      # Output is False

Comparison: isalpha() vs isalnum() and isdecimal()

text = "Python123"
print(text.isalpha())   # False (contains digits)
print(text.isalnum())   # True (contains letters and digits)
print(text.isdecimal()) # False (contains letters)

Use Case: Form Validation

Check if a user's name input contains only letters:

name = input("Enter your name: ")
if name.isalpha():
    print("Valid name")
else:
    print("Invalid name")

Example 2: Using isalpha() with Spaces or Symbols

Spaces and symbols cause `isalpha()` to return False.
text = "Hello World!"
print(text.isalpha())  # Output: False

Example 3: Validating User Input

Use `isalpha()` to ensure user input contains only letters.
name = input("Enter your name: ")
if name.isalpha():
    print("Valid name.")
else:
    print("Invalid input: Use alphabet characters only.")

Applications of isalpha()

  • Input Validation: Ensure names and other alphabetic fields contain only letters.
  • Text Processing: Identify purely alphabetic words in text data.
  • Conditional Formatting: Apply conditional logic based on alphabet-only text.


All String methods


Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer