字符串:各种奇葩内置--2017/9/3--2
2017-09-03 15:35
204 查看
字符串和元组很像
str1[1]
‘b’
字符串不能更改
str2=’biubiu’
capitalize 首字母大写
str2.capitalize()
‘Biubiu’
casefold 全部小写
str2.casefold()
biubiu
capitalize casefold 得到新字符串,strt2不变
count(start[,start[,end) 出现次数
str2.count(xi)
endswith 解释是否为xx
str2.endswith(xi)
startswith 开始是否为xx
expendtabs \t加空格,默认8(a个空格,8-a个空格)
str2.expendtabs(‘B\tiubi\tu’)
‘B iubi u’
find xx是否在字符串中,有-返回索引值,无-返回-1
rfind 右边找
index 与find一致,只是无返回异常
rindex
isalnum >1个字符并且所有均为数字或字符,T
isdigit all数字,T
islower all小写,T
isupper all大写,T
isnumeric all数字字符,T
isspace all空格,T
title 标题化(首字母大写,后面全小写)
istitle 首字母大写,后面全小写,T
join(sub)
str2=’biubiu’
str2.jion(123)
‘1biubiu2biubiu3’
123被隔开
ijust 左对齐
lower 大写变小写
upper
strip 首尾去掉,默认为空格
istrip 去掉左边所有空格
rstrip 右边
partition 找到sub,分成三个字符
str2=’biubiu’
str2.partition(‘iu’)
(‘b’,’iu’,’biu’)
rpartition
replace(old,new[,count) count 最多可替换数
split(sub) 找到sub就切,变成列表;默认为空格
splitlines \n为分隔
swapcase 大小写转换
translate()
str2=’biubiu’
str2.translate(str.maketrans(‘b’,’w’))
‘wiuwiu’
zfill 右对齐,前面用0填充
str1='abcd' str1[:1] 'ab'
str1[1]
‘b’
字符串不能更改
str2=’biubiu’
capitalize 首字母大写
str2.capitalize()
‘Biubiu’
casefold 全部小写
str2.casefold()
biubiu
capitalize casefold 得到新字符串,strt2不变
count(start[,start[,end) 出现次数
str2.count(xi)
endswith 解释是否为xx
str2.endswith(xi)
startswith 开始是否为xx
expendtabs \t加空格,默认8(a个空格,8-a个空格)
str2.expendtabs(‘B\tiubi\tu’)
‘B iubi u’
find xx是否在字符串中,有-返回索引值,无-返回-1
rfind 右边找
index 与find一致,只是无返回异常
rindex
isalnum >1个字符并且所有均为数字或字符,T
isdigit all数字,T
islower all小写,T
isupper all大写,T
isnumeric all数字字符,T
isspace all空格,T
title 标题化(首字母大写,后面全小写)
istitle 首字母大写,后面全小写,T
join(sub)
str2=’biubiu’
str2.jion(123)
‘1biubiu2biubiu3’
123被隔开
ijust 左对齐
lower 大写变小写
upper
strip 首尾去掉,默认为空格
istrip 去掉左边所有空格
rstrip 右边
partition 找到sub,分成三个字符
str2=’biubiu’
str2.partition(‘iu’)
(‘b’,’iu’,’biu’)
rpartition
replace(old,new[,count) count 最多可替换数
split(sub) 找到sub就切,变成列表;默认为空格
splitlines \n为分隔
swapcase 大小写转换
translate()
str2=’biubiu’
str2.translate(str.maketrans(‘b’,’w’))
‘wiuwiu’
zfill 右对齐,前面用0填充
相关文章推荐
- Python-10 字符串-各种奇葩的内置方法
- 2、Python之字符串的各种奇葩的内置方法
- 零基础入门学习Python(14)--字符串:各种奇葩的内置方法
- 【零基础入门学习Python笔记014】字符串:各种奇葩的内置方法
- 5.字符串:各种奇葩的内置方法/格式化
- 零基础入门学习Python(14)--字符串:各种奇葩的内置方法
- 014:字符串:各种其奇葩的内置方法
- FishC笔记—14 讲 字符串:各种奇葩的内置方法
- 字符串:各种奇葩的内置方法 - 零基础入门学习Python014
- 学习笔记-小甲鱼Python3学习第十四讲:字符串:各种奇葩的内置方法
- leetcode——8 String to Integer (atoi)(自定义字符串转整型,如何避开各种奇葩输入)
- 字符串的各种内置方法
- 收集常用的Python 内置的各种字符串处理 函数的使用方法
- python 字符串str各种内置方法
- 各种字符串类型的转换
- 各种数转换成字符串
- 各种字符串Hash函数比较
- js字符串的各种格式的转换 ToString,Format
- Visual C++ 如何:在各种字符串类型之间进行转换
- Java各种字符串连接方法性能比较