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 祝福语驱散霉运的话简短