Ayxan
0
Q:

capitalize string python

msg = "good night"
print(msg.capitalize())
#output: Good night
14
# 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."

# ---------- Alternate Title Case ----------
# "This Isn't A #standard Sentence."

from string import capwords
string = capwords(string) # capitalize characters after each separator.
# see the doc: string.capwords(s, sep=None), separator defaults to space

# or implement it directly:
string = " ".join(s.capitalize() for s in string.split())
#
0
str.capitalize() # This is will capitalize your string
7
message="hi"
print(message)
print(message.upper())
1

New to Communities?

Join the community