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


Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    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 FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer