python学习-字符串操作
来源:互联网 发布:单片机数字式温度计 编辑:程序博客网 时间:2024/05/17 23:31
记录几个平时使用较少的方法,加深印象
1、string.capatize(self)
- 对首字母进行大写转换
name = 'yanzu wu'print(name.capitalize())
输出
Yanzu wu
2、string.center(self, width, fillchar)
- 输出一个长度为width的字符串,string居中,其余使用fillchar填充
name = 'yanzu wu'print(name.center(30, '='))
输出
===========yanzu wu===========
3、string.format(self, args, kwargs)
- 格式化字符串输出
msg = 'hello {name},welcome to {location}'msg2 = 'hello {0},welcome to {1}'print(msg.format(name = 'wuyanzu', location = 'shanghai'))print(msg2.format('wuyanzu', 'shanghai'))
输出
hello wuyanzu,welcome to shanghai
hello wuyanzu,welcome to shanghai
4、string.find(self, sub, start, end)
- 输出找到的字符的位置(多个只返回第一个),未找到则返回-1。sub为指定的字符串,start、end可不填,指定搜索范围的起始和结束为止。
name = 'yanzu wu'print(name.find('u'))print(name.find('e'))
输出
4
-1
0 0
- Python学习---字符串操作
- python学习:字符串操作
- Python学习-字符串操作
- python学习-字符串操作
- python学习:字符串切片操作
- python学习006--字符串操作
- Python学习(字符串操作)
- python字符串操作学习小结
- Python学习3:字符串操作
- python的学习(五)----字符串操作
- Python学习笔记:字符串基本操作
- Python学习笔记--字符串操作string
- Python学习13:字符串操作函数使用
- Python学习(三): 字符串操作
- python学习笔记(字符串常见操作)
- python学习笔记之二:字符串操作
- python学习五(字符串操作)
- python学习 原始字符串操作符 print
- Android传感器之摇一摇与指南针
- 链表问题:如何反转链表?
- 利用Python递归列举目录下的文件并进行有序的排列
- 面向对象程序设计上机练习七(类和对象)
- BGP 配置
- python学习-字符串操作
- hdu BFS 2952
- Outlook2013/2016中的Gmail设置
- hdu 2795 billboard(线段树)
- ServletConfig和ServletContext接口
- Ubuntu16.04下python+PyCharm开发环境的搭建
- [dfs 离线] Hillan模拟赛 C.可持久化的书橱
- ecshop数据库表6(ecs_admin_user)管理表
- Caffe中crop_layer层的理解和使用