xxxxxxxxxx
s = "hello openGeNus"
t = s.title()
print(t)
PythonCopy
xxxxxxxxxx
my_string = "programiz is Lit"
cap_string = my_string.capitalize()
print(cap_string)
xxxxxxxxxx
my_string = "programiz is Lit"
print(my_string[0].upper() + my_string[1:])
xxxxxxxxxx
my_string = "car"
my_string.upper() # Makes EVERY letter uppercase
print(my_string)
>>> "CAR"
my_string = "car"
my_string.title() # Makes ONLY FIRST letter uppercase and others lowercase
print(my_string)
>>> "Car
xxxxxxxxxx
text ="welcome to PYTHON Tutorial"
# capitalizes the first letter in string
# and keeps the rest of the string in lowercase
captialized_text= text.capitalize()
print(captialized_text)
xxxxxxxxxx
def n_upper_chars(string):
return sum(map(str.isupper, string))
xxxxxxxxxx
capitalize() - Converts the first character to upper case # e.g. "grepper".capitalize() => "Grepper"
xxxxxxxxxx
# Python string capitalization
string = "this isn't a #Standard Sntence."
string.capitalize() # "This isn't a #standard sentence."
string.upper() # "THIS ISN'T A #STANDARD SENTENCE."
string.lower() # "this isn't a #standard sentence."
string.title() # "This Isn'T A #Standard Sentence."
xxxxxxxxxx
In [48]: x = 'Linux'
In [49]: x[0].isupper()
Out[49]: True
In [51]: x = 'lINUX'
In [53]: x[0].isupper()
Out[53]: False