capitalize()函数实例详解
返回函数主目录 | |
capitalize() 将字符串的第一个字母变成大写,其他字母变小写。 | |
语 法 | capitalize() 方法语法:str.capitalize() |
参 数 | 无 |
注 意 | 1、一般情况下,字符串首字符会转换成大写,字符串其余字符会转换成小写。 2、字符串首字符如果是数字,首字母不会转换成大写。 3、字符串首字符如果是非字母符号,字符串首字母不会转换成大写,会转换成小写。 4、字符串首字符如果是空格,字符串首字母不会转换成大写,会转换成小写。 |
返 回 值 | 该方法返回一个首字母大写的字符串 |
实 例 | |
代 码 | str = "while there is life, there is hope!!!" print ("str.capitalize() : ", str.capitalize()) |
运行结果 | str.capitalize() : Where there is life, there is hope!!! |
代 码 | str = " where there is life, there is hope!!!" print ("str.capitalize() : ", str.capitalize()) |
运行结果 | str.capitalize() : where there is life, there is hope!!! |
代 码 | str = "where there IS LIFE, There is hope!!!" print ("str.capitalize() : ", str.capitalize()) |
运行结果 | str.capitalize() : Where there is life, there is hope!!! |
代 码 | str = "123where there IS LIFE, There is hope!!!" print ("str.capitalize() : ", str.capitalize()) |
运行结果 | str.capitalize() : 123where there is life, there is hope!!! |
代 码 | str = "&where there IS LIFE, There is hope!!!" print ("str.capitalize() : ", str.capitalize()) |
运行结果 | str.capitalize() : &where there is life, there is hope!!! |
代 码 | str = "hello 逆境清醒" print ("str.capitalize() : ", str.capitalize()) |
运行结果 | str.capitalize() : Hello 逆境清醒 |
代 码 | str = "逆境清醒 HELLO " print ("str.capitalize() : ", str.capitalize()) |
运行结果 | str.capitalize() : 逆境清醒 hello |
代 码 | str = "012345" print ("str.capitalize() : ", str.capitalize()) |
运行结果 | str.capitalize() : 012345 |
代 码 | str = " " print ("str.capitalize() : ", str.capitalize()) |
运行结果 | str.capitalize() : |
代 码 | |
运行结果 | |
推荐阅读:
29 |
| svg实例详解系列(一) |
28 |
| |
27 |
| |
26 |
| 2023年春节祝福第二弹——送你一只守护兔,让它温暖每一个你【html5 css3】画会动的小兔子 |
25 |
| 2023春节祝福系列第一弹(放飞祈福孔明灯,祝福大家身体健康)(附完整源代码及资源免费下载) |
24 |
| |
23 |
| |
22 |
| |
21 |
| python爱心源代码集锦 |
20 |
| 巴斯光年python turtle绘图__附源代码 |
19 |
| Three.js实例详解___旋转的精灵女孩(附完整代码和资源) |
18 |
| |
17 |
| |
16 |
| |
15 |
| |
14 |
| |
13 |
| |
12 |
| |
11 |
| 用代码写出浪漫__合集(python、matplotlib、Matlab、java绘制爱心、玫瑰花、前端特效玫瑰、爱心) |
10 |
| |
9 |
| |
8 |
| |
7 |
| |
6 |
| |
5 |
| |
4 |
| |
3 |
| |
2 |
| |
1 |
|