字符串python

#字符串
#用户登录界面  手机号以字符串输入 密码:区分大小写  验证码:不区分大小写(字符串的转化和对比)
#截取文字(字符串的截取)
#查找与替换(字符串的查找、字符串的替换、字符串的长度的统计)

my_introduce='my name is xxx,I like python'
upper_my_introduce=my_introduce.upper() #大写
print(upper_my_introduce)
lower_my_introduce=my_introduce.lower() #小写
print(lower_my_introduce)
#a.title() 首字母大写

#find() 返回索引(下标)
x_index=my_introduce.find('xxx')
print(x_index)
x_index=my_introduce.find('xxx',0,15)
print(x_index)

l=len(my_introduce) #len()统计长度
print(l)
if l<30:
    print('自我介绍不能低于30字')

c=my_introduce.count('m',2,10)  #统计m出现的次数
print(c)

#文本布局 center() rjust() ljust()      strip() rstrip() lstrip()
#居中对齐 、居右 、居左 、               去除两边空格、去除右边空格、去除左边空格

#截取 拼接 分割 替换 比较
#切片:【起始位置:终止位置:步长】 包含起始位置,不包含终止位置
name=my_introduce[11:14:1]
print(name)

ym=my_introduce[30:0:-1] #倒着截取  不包含0
print(ym)
ym=my_introduce[30::-1] #包含30到0的所有数   如果需要截取到头,省略不写。不能写-1
print(ym)

#拼接  +
sub1_str='my name is xxx,'
sub2_str='I like python'
str=sub1_str+sub2_str
print(str)

#分割 split
words=str.split(' ')  #用''分割
print(words)

#替换 replace
new_str=str.replace('xxx','侯老师')
print(new_str)

#1.字符串的内容比较 2.比较两个字符串是不是同一个字符串
pwd1=input('请输入密码:')
pwd2=input('请再次输入密码:')

#比较内容是否一样
if pwd1==pwd2:
    print('两次一样')
else:
    print('两次不一样')
#身份运算符
if pwd1 is pwd2:
    print('pwd1和pwd2是同一个字符串')
else:
    print('pwd1和pwd2不是同一个字符串')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值