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

python数据类型之str用法

时间:2016-04-24 00:34:39      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

 

1、首字母大写

语法:S.capitalize() -> str

title = "today is a good day"
title_ca = title.capitalize()
print(title_ca)

结果:today is a good day

2、大写转小写

1 语法:S.casefold() -> str
2 
3 title = "TODAY is a GOOD day"
4 title_ca = title.casefold()
5 print(title_ca)

结果:Today is a good day

3、字符串居中

c = kong

ret = c.center(10,*)
print(ret)

结果:***kong***

 4、字符串子串数量统计

S.count(sub[, start[, end]]) -> int

title = "today is a good day"
title_ca = title.count(y,1,5)
print(title_ca)

结果:1

 

python数据类型之str用法

标签:

原文地址:http://www.cnblogs.com/kongzhagen/p/5426064.html

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