Python‎ > ‎str‎ > ‎

str.isalpha()

http://www.adilwaseem.com/

Introduction
Return True if the string has only one characters.

Syntax
str.isalpha('x')-> bool

Parameters
x=string

Examples
The method can be tested these ways.
 >>> 
>>> "Q".isalpha()
True
>>> str.isalpha("Q")
True
>>> x="Q"
>>> x.isalpha()
True
>>>

The method tested that whether the string is single character.
 >>> 
>>> x="python Learning Centre"
>>> x.isalpha()
False
>>> x.isalpha()
False
>>> x="P"
>>> x.isalpha()
True
>>> 

if statement 
The method is tested through if statement.
 Name=str(input("Please enter your name: "))
if str.isalpha(Name):
print("Name can be single character.")
else:
print("Okay")
>>> 
Please enter your name: p
Name can be single character
>>>

class.....: def __init__()......:....str.isapha()==True
The function tested whether the string value is single word, or contain non-string values through input().
 class str_methods():
    def __init__(self, a,b,c):

        identifier=str.isidentifier(a)

        if str.isidentifier(a).__eq__(True):
            print("Full name should not contain special characters or numbers")
            
        else:
            print("Your full not name accepted")

        
      
        alpha=str.isalpha(b)
        
        if alpha.__ne__(False):
            print("Full name accepted")

            lower=str.lower(c)
            if lower.__eq__(str.lower(c)):
                 str.upper(c)
                 print("System convert your name to uppercase:", str.upper(c))
            else:
                 print("Your name accepted")

        else:
            print("Full name can't be one word")

                    

input_text=input("Please enter  your full name: ")

str_methods(input_text, input_text,input_text)
    
          

>>> 
Please enter your full name: Adil22
Full name should not contain special characters or numbers
Full name can't be one word
>>>        


Comments