码迷,mamicode.com
首页 > 编程语言 > 详细

Python 首字母大写

时间:2020-06-23 10:19:46      阅读:59      评论:0      收藏:0      [点我收藏+]

标签:src   自定义   mic   color   需求   技术   inf   title   方法   

python  内置首字母大写的方法title(),可以满足一般的需求 ,但是title()方法 会把除了首字母之外的字母变为小写 ,这时候就需要自定义首字母大写的方法了

1 # 首字母大写
2 def firstUp(title):
3     new_str = {}{}.format(title[0].upper(), title[1:])
4     return new_str

 

测试:

技术图片

 

 

执行结果

技术图片

 

Python 首字母大写

标签:src   自定义   mic   color   需求   技术   inf   title   方法   

原文地址:https://www.cnblogs.com/sunxun001/p/13180597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!