python数据类型常用内置函数之字符串
2024-09-30 10:54:03
1、strip, lstrip, rstrip
x = ' jiahuifeng '
print(x.strip(' '))
print(x.lstrip(' '))
print(x.rstrip(' '))
2、lower ,upper
x = 'jiahuifeng'
print(x.lower())
print(x.upper())
3、startswith,endswith
x = 'fengjiahui_haha'
print(x.startswith('fe'))
print(x.endswith('_haha'))
4、格式化输出
print('My name is %s,my age is %s' %('jiahuifeng',18))
print('{} {} {}'.format('jiahuifeng',18,'male'))
5、split , splitlines
name='root:x:0:0::/root:/bin/bash'
print(name.split(':')) #默认分隔符为空格 name='C:/a/b/c/d.txt' #只想拿到顶级目录
print(name.split('/',1)) name='a|b|c'
print(name.rsplit('|',1)) #从右开始切分 name = '''ab c
de fgkl
sadfewf'''
print (name.splitlines())
6、join
name=' '
print(tag.join(['egon','say','hello','world'])) -->egon say hello world
7、replace
name='jiahuifeng say :i have one apple,my name is jiahuifeng'
print(name.replace('jiahuifeng','qiqi',1))
8、拼接
x = 'jiahuifeng'
y = 'shi'
z = 'haha' name = x+y+z
print(name)
最新文章
- IOS 开发中 Whose view is not in the window hierarchy 错误的解决办法
- Premiere Pro &; After Effects插件开发调试方法
- 如何获得DataGrid中某行某列的对象
- Python开发【第十二篇】:DOM
- [Cocos2d-x For WP8]ActionManager动作管理
- U-boot.lds文件分析
- C++中数组求偏移量计算公式
- oracle数据库导入导出命令!
- 命令行下玩VC
- Jquer学习
- mysql嵌套查询
- C#调用SAPWebService
- MVC模式编程演示样本-登录认证(静态)
- PPPOE拨号上网流程及密码窃取具体实现
- 1 开发环境 eclipse oomph版本 jdk1.8 lucene 6.6.0,luke6.6.0
- 51Nod1824 染色游戏 【Lucas定理】【FMT】【位运算】
- Python3学习笔记21-实例属性和类属性
- Notes for Neural Network Methods for Natural Language Processing
- angularjs初识ng-app、ng-model、ng-repeat指令
- 【BZOJ2164】采矿 树链剖分+线段树维护DP
热门文章
- .NETFramework:Stream
- ASP.NET Core:template
- 架构-MVVM:MVVM核心概念
- opencord视频截图
- HDU 5879 Cure (数论)
- J20170426-hm
- dijkstra算法的应用(poj2387)+堆优化【还没学C艹很尴尬,不理解的先不写了,未完,待续...】
- 第十二篇 .NET高级技术之lambda表达式
- 温习LOGO语言
- Codeforces Round #408 (Div. 2) A