python单词首字母大写
Here, we are implementing a python program to capitalizes the first letter of each word in a string.
在这里,我们正在实现一个python程序来大写字符串中每个单词的首字母。
Example:
例:
Input: "HELLO WORLD!"
Output: "Hello World!"
Method 1: Using title() method
方法1:使用title()方法
# python program to capitalizes the
# first letter of each word in a string
# function
def capitalize(text):
return text.title()
# main code
str1 = "Hello world!"
str2 = "hello world!"
str3 = "HELLO WORLD!"
str4 = "includehelp.com is a tutorials site"
# printing
print("str1: ", str1)
print("str2: ", str2)
print("str3: ", str3)
print("str4: ", str4)
print()