Python | 带有示例的string.upper(),string.lower()和string.title()方法
string.upper(),和的方法是在Python内置方法,这些被用来格式字符串在像转换为大写,小写或小的情况下格式的特定格式。string.lower()string.title()
1)string.upper()
方法返回大写字符串(字符串的所有字符均为大写)。
示例:“HELLOWORLD”
2)string.lower()
方法返回小写字符串(字符串中的所有字符均小写)。
示例:“helloworld”
3)string.upper()
方法返回标题大小写字符串(每个单词的第一个字符为大写,其余所有字符为小写)。
示例:“HelloWorld”
语法:
string.upper()
string.lower()
string.title()范例1:
#声明一个字符串 str = "HELLO World How are you?" #大写字符串 print "Uppercase string: ",str.upper() #小写字符串 print "Lowercase string: ",str.lower() #标题大小写字符串 print "Title case string: ",str.title()
输出结果
Uppercase string: HELLO WORLD HOW ARE YOU?
Lowercase string: hello world how are you?
Title case string: Hello World How Are You?热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短