字符串之常用方法

strip(移除两边的符号)
msg='abc'
msg.strip(*) ---->'abc'
1.2
lstrip(用法和strip相同但只能移除左边的符号)
1.3
rstrip(用法和strip相同但只能移除右边的符号)

lower(将字符串全部转化为小写)
msg.lower(msg)
upper(将字符串全部转化为大写)
msg,upper(upper)

startswith,endswith
作用:判断开头和结尾
msg='abc is ok'
msg.startswitch('abc')

split,rsplit
作用:将字符串切片成列表
info='hello world'
info.split('😂 ----->['hello','world']
(rsplit是反向切片)

join
作用:将列表拼接成字符串
list1=['hello','world']
':'.join(list1) ------>'hello world'

replace
作用:替换功能
msg='you can you up'
msg.replace('you','YOU') ---->'YOU can YOU up'

isdigit
作用:判断字符串是否由纯数字组成
'abc'.isdigit() ----->False
'1ad'.isdigit() ----->False
'123'.isdigit() ----->True

posted @ 2020-03-10 19:44  江湖有梦  阅读(168)  评论(0编辑  收藏  举报