python 3.0 字符串的操作

#String的内置方法

st='hello w\torld'

1、print(st.count('l'))  #统计元素在字符串的个数

#==> 3

2、print(st.capitalize()) #首字母大写

#==> Hello world

3、print(st.center(50,'-'))  #字符串居中

#==> -------------------------hello world-------------------------

4、print(st.endwith('rld')) #判断结尾元素

#==>True

5、print(st.startswith('hello')) #判断开头元素

#==>True

6、st='hello w\torld'

print(st.expandtabs(tabsize = 10))

#==> hello w          orld

7、print(st.find('t')) #查找到第一个元素并将其索引值返回

#==> 8

8、

猜你喜欢

转载自www.cnblogs.com/Karenbest/p/8974351.html