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?热门推荐
1 如何训练狗狗握手
10 新员工寄语祝福语简短
11 新婚敬酒祝福语大全简短
12 怎么训练狗狗
13 训练狗狗上厕所
14 春蚕老师祝福语简短励志
15 高考好运如愿祝福语简短
16 战哥过年祝福语简短
17 中考感谢朋友祝福语简短
18 长沙旅游祝福语大全简短