20220125python第二日整形字符串方法

1.实现用户账号密码校验登录(已实现)

count=0
right_accond='admin'
right_password='666;8'
whlie count<3:
    user=input('input your accond')
    password=input('input your password')
    if user==right_accond and password==right_password:
        print('you are loge in.')
        break
    else:
        print('worng accond')
    count=count+1
else:
    print('you are out off choice.')

2.pycharm安装(需要注册,安装失败,继续用python)
create new-pythone 35

3.运算符 and、or没有优先级

4.数据类型的方法:
int:
    type(变量)
    int(变量,base=2) 
    #强制类型转换,转换为2进制

    num='b'
    v=int(num,base=16)
    #转换为16进制输出
    print(v)

    age=23
    #表示数据2进制长度
    r=age.bit_length()
    print(r)
string:
    test='alexddbcex'
    
    #首字母大写
    v=test.capitalize()
    #大写变小写,casefold()可以变化未知道的对应关系
    test.casefold()
    test.lower()
    #放中间(20个长度,空白位置填充一个字符)
    test.center(20,‘*’)
    #计算r的个数,开始位置,结束位置
    test.count('r',5,8)
    #判断是否以a结尾
    test.endwith('a')
    #判断是否以a开头
    test.startwith('a')
    #从开始往后找,找到第一个,返回位置。从5开始,7结束。开区间
    test.find('ex',5,7)
    #替换指定值
    test='I am {name}'
    test.format(name='alex')
    #按顺序替换指定值
    test='I am {0},age {1}'
    test.format('alex',23)

    #按顺序替换指定值
    test='I am {name},age {age}'
    test.format_map(name:'alex',age:23)
    #找索引,找不到报错
    test.index('a')

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值