python字符串_自学

mystr='a project is a task that requires a lot of time and efforts'
newstr='less is more'
senstr='lessismore'
thstr='12323'
forstr='sasd33'
fivstr=' '

print(mystr.find('p')) #查找字符串中是否包含特定字符,有则返回下标,否则false

print(mystr.index('p')) #同上

print(mystr.count('p'))#查找字符串中特定字符出现的次数

print(mystr.title())#字符串中每个首字母大写

print(mystr.lower())#字符串中每个字母小写

print(mystr.upper())#字符串中每个字母大写

print(mystr.split(' '))#按分割符分割字符

print(mystr.replace('t', 'W'))#替换字符内容

print(mystr.capitalize())#字符串第一个字母大写

print(mystr.lstrip())#从字符串左侧开始去除空格

print(mystr.rstrip())#从字符串右侧开始去除空格

print(newstr.startswith('1'))#检测字符串是否以某个字母开头

print(newstr.endswith('e'))#检测字符串是否以某个字母结尾

print(senstr.isalpha())#检测字符串是否全部都是字母

print(thstr.isdigit())#检测字符串是否全部都是数字

print(thstr.isalnum())#检测字符串是否全部都是字母或数字

print(fivstr.isspace())#检测字符串是否全部都是空格
 

mystr='a project is a task that requires a lot of time and efforts'
newstr='less is more'
senstr='lessismore'
thstr='12323'
forstr='sasd33'
fivstr=' '

print(mystr.find('p')) #查找字符串中是否包含特定字符,有则返回下标,否则false

print(mystr.index('p')) #同上

print(mystr.count('p'))#查找字符串中特定字符出现的次数

print(mystr.title())#字符串中每个首字母大写

print(mystr.lower())#字符串中每个字母小写

print(mystr.upper())#字符串中每个字母大写

print(mystr.split(' '))#按分割符分割字符

print(mystr.replace('t', 'W'))#替换字符内容

print(mystr.capitalize())#字符串第一个字母大写

print(mystr.lstrip())#从字符串左侧开始去除空格

print(mystr.rstrip())#从字符串右侧开始去除空格

print(newstr.startswith('1'))#检测字符串是否以某个字母开头

print(newstr.endswith('e'))#检测字符串是否以某个字母结尾

print(senstr.isalpha())#检测字符串是否全部都是字母

print(thstr.isdigit())#检测字符串是否全部都是数字

print(thstr.isalnum())#检测字符串是否全部都是字母或数字

print(fivstr.isspace())#检测字符串是否全部都是空格

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值