Python‎ > ‎str‎ > ‎

str.capitalize()

http://www.adilwaseem.com/

Definition
Return a capitalized version of S, i.e. make the first character have upper case and the rest lower case.

str.capitalize()
str.capitalize(x)

Parameters
str=string
x=string

Examples
Syntax
The string method results on is not is:
 >>> "Python".capitalize() is not "PYTHON"
True
>>> x="Python".capitalize()


The tkinter.Entry is used to check the string characteristics through string methods.

master=Tk()
master.title("String methods")

def cap():
    try:
        c=str.capitalize(s.get())
        s.set(c)
        
        pass

def cfold():
    try:
        c=str.casefold(s.get())
        s.set(c)
        
    except ValueError:
        pass

def ifier():
    try:
        if str.isidentifier(s.get())==True:
            s.set("Yes")
        
        else:
            s.set("No")
        
    except ValueError:
        pass

def ipace():
    try:
        if str.isspace(s.get())==True:
            s.set("Yes")
        
        else:
            s.set("No")

    except ValueError:
        pass

def iric():
    try:
       if str.isnumeric(s.get())==True:
           s.set("Yes")
       else:
           s.set("No")        
                
    except ValueError:
        pass

def ower():
    try:
        if str.islower(s.get())==True:
            s.set("Yes")
        
        else:
            s.set("No")        
        
    except ValueError:
        pass

def inum():
    try:
        if str.isalnum(s.get())==True:
            s.set("Yes")
        
        else:
            s.set("No")        
    except ValueError:
        pass

def imal():
    try:
        if str.isdecimal(s.get())==True:
            s.set("Yes")
        
        else:
            s.set("No")
        
    except ValueError:
        pass

    

def igit():
    try:
        if str.isdigit(s.get())==True:
            s.set("Yes")
        
        else:
            s.set("No")
        
    except ValueError:
        pass


def clr():
    try:
        s.set("")
        
              
    except ValueError:
        pass



entry=Entry(master, textvariable=s)
entry.grid(row=0, columnspan=4, sticky=W+E)


button_capitalize=Button(master, text="capitalize", width=10, command=cap)
button_capitalize.grid(row=2, column=0)

button_casefold=Button(master, text="casefold",width=10, command=cfold)
button_casefold.grid(row=2, column=1)

button_isidentifier=Button(master, text="isidentifier",width=10,command=ifier)
button_isidentifier.grid(row=2, column=2)


button_isspace=Button(master, text="isspace",width=10, command=ipace)
button_isspace.grid(row=3, column=0)

button_endswith=Button(master, text="endswith", width=10, command=iric)
button_endswith.grid(row=3, column=1)

button_islower=Button(master, text="islower",width=10, command=ower)
button_islower.grid(row=3, column=2)



button_isalnum=Button(master, text="isalnum",width=10, command=inum)
button_isalnum.grid(row=4, column=0)

button_isdecimal=Button(master, text="isdecimal",width=10, command=imal)
button_isdecimal.grid(row=4, column=1)

button_isdigit=Button(master, text="isdigit",width=10, command=igit)
button_isdigit.grid(row=4, column=2)

button_clear=Button(master, text="Clear", command=clr )
button_clear.grid(row=5, columnspan=3,sticky=W+E)












capitalizing input(str)
The method returns with capitalizing the input().
 name1=input("Enter your name: ")
if name1.lower():
        print("Your name is: ", name1.capitalize())
>>> 
Enter your name: adil
Your name is: Adil
>>> 

string.capwords
The string method string.capwords is used to capitalize the string.
 >>> string.capwords("adil waseem")
'Adil Waseem'
>>> string.capwords("python research Centre")
'Python Research Centre'
>>>


The return are:
 >>> str.capitalize("python").__eq__("Python")
True
>>> str.capitalize("python lake").__eq__("Python Lake")
False
>>> str.capitalize("python lake").__eq__("Python lake")
True
>>> str.capitalize("python lake").__ne__("Python Lake")
True

class...: def:.....:str.capitalize()
The class return after capitalizing the strings.
 class string_capitalize:
    def __init__(self,a,b):

        self.a=str.capitalize(a)
        self.b=str.capitalize(b)
        print(a, b)
        

x="python"
y="lake"

string_capitalize(x,y)



>>> 
Python Lake
>>> 



Comments