字符串:系统内置方法

1.不使用系统内置方法操作字符串

>>> str = '程序员'
>>> str1 = str[:1] +'(加)' + str[1:2] + '(班)' + str[2:]
>>> str1
'程(加)序(班)员'

2.内置函数

  capitalize() 转换首字母为大写

>>> str = 'python'
>>> str.capitalize()
'Python'
>>> 

  casefold() 转换所有字符为小写

>>> str.casefold()
'python'
>>> 

  count(sub[,start[,end]]) 返回子串sub在字符串中出现的次数,start和end指定范围

>>> str = 'PYTHON'
>>> str.count('O')
	      
1

  区分大小写

原文地址:https://www.cnblogs.com/xiangdongsheng/p/13414490.html