Python str upper方法 |
您所在的位置:网站首页 › upper怎么用python › Python str upper方法 |
目录 描述 语法 参数 返回值 使用示例 注意事项 1. 字符串原本存在大写字母时 2. 字符串存在非字母字符 描述upper()方法是Python的字符串方法,它将字符串中的小写字母转换成大写字母,并返回转换后的字符串。 语法 str.upper() 参数upper()方法没有参数 返回值返回一个修改后的新字符串 使用示例upper()方法将字符串中的非大写字母转换成大写,并返回新的字符串。 >>> demo = "Welcome to Beijing." >>> id(demo) 4467791816 >>> result = demo.upper() >>> result 'WELCOME TO BEIJING.' >>> id(result) 4467791960 注意事项 1. 字符串原本存在大写字母时在使用upper()方法之前字符串原本就存在大写字母时,upper()方法将保留大写字母,并将小写字母转换成大写字母。 >>> demo = "Golang is a new language." >>> demo 'Golang is a new language.' >>> demo.upper() 'GOLANG IS A NEW LANGUAGE.' 2. 字符串存在非字母字符upper()不会处理非字母字符,更不会报错。 >>> demo = "??" >>> demo '??' >>> demo.upper() '??' |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |