参考:https://www.cnblogs.com/cookie1026/p/6048092.html
#!/usr/bin/env python
# -*- coding:utf- -*-
s = 'abcd'
ss = 'this is cash'
print s.ljust(,'w')#返回一个原字符串右用字符串0填充左对齐并宽度7的新字符串
print s.rjust(,'-')
print s.center(,'*')#表示原字符串居中两边填充宽度的用法
print ss.center(,' ') print format(ss,'.3')

本文主要介绍了字符串的使用,可以进行字符串切片、字符串长度统计、查找、替换、大小写转换等。

打印结果如下:

#!/usr/bin/env python
# -*- coding:utf- -*-
s = 'aBcdkwwqerD'
ss = '12 this is cash'
print ss.find('th') #检查是否包含在指定范围内,如果包含子字符串返回开始的索引值,否则返回-。
print ss.find('is')
print ss.find('it') print s.upper(),'--->upper方法' #将小写字母转换成大写字母
print s.lower(),'--->lower方法' #将大写字母转换成小写字母
print ss.isdigit(),'--->isdigit方法' #判断字符串如果是数字返回真True,不是返回假False
print s.startswith('ab'),'--->startswith方法' #判断字符串是否是以abc开头如果是返回真,否则返回假
print s.endswith('D'),'--->endswith方法' #判断字符串是否以yz结尾是返回真,否则返回假 print s.partition("k") #生成一个分隔符k,第一个为分隔符左边的子串,第二个为分隔符本身,第三个为分隔符右边的子串。

打印结果:

最新文章

  1. swift3.0:associatedtype
  2. ajax onblur 用法
  3. Eclipse中user library包管理
  4. [转]C/C++中的memset
  5. jquery plugins —— datatables 增加行号
  6. VIM 及其插件使用快捷键汇总
  7. Topcoder SRM 639 (Div.2)
  8. Effective C++:条款35:考虑virtual函数以外的其它选择
  9. HDU 4034 Graph(Floyd变形——逆向判断)
  10. 常见的web测试功能点测试思路
  11. Windows 与Office 镜像的区别
  12. spring事务源码分析结合mybatis源码(三)
  13. 一个可以配置阴影方向和颜色的类 CardView 控件 SCardView
  14. 0003 - 基于xml的Spring Bean 的创建过程
  15. animation 老动画
  16. report源码分析——report_handle和report_server和report_catcher
  17. LambdaAOP
  18. 计算Python运行时间
  19. LeetCode题解之Merge Two Sorted Lists
  20. ZT pthread_cleanup_push()/pthread_cleanup_pop()的详解

热门文章

  1. CSS盒子模型(Box Model)
  2. c/c++ 继承与多态 子类隐藏父类的同名非虚函数
  3. Task.Wait and “Inlining”
  4. 我的第一个python web开发框架(26)——定制ORM(二)
  5. Redis学习笔记(2)——Redis的下载安装部署
  6. Hadoop Compatibility in Flink
  7. centos7下kubernetes(13。kubernetes-探讨service IP)
  8. 22 python 初学(类,面向对象)
  9. 检测web界面不能访问后重启
  10. Visual Studio中Image Watch的使用