数据类型的一些方法

统计3出现了多少次
l=[1,2,3,3,3]
print(l.count(3))


一,整型,int
    记录年龄等整数
    age =18  age=int(18)
    数据类型转换
    n = int('12344445')
    必须纯数字
    不可变类型    

二.浮点类型,float
    age = 2.33  age = float(2.33)
    也是不可变类型
    
三.进制转换
    print(hex(11))
    print(bin(11))
    print(oct(11))

四.字符串
    name = 'kevin'
    name = str(kevin)
    1.按索引取值
        msg ='apple'
        print(msg[0])
        print(msg[-1])
    2.切片
        msg ='apple'
        print(msg[0:5:1])正取步长为1
        print(msg[::-1])反取步长为-1
    3.长度
        len()
    4.成员运算
        in 和  not in
    5.移除空白
        移除左右两边的空白
        msg= '***sdf***'
        msg.strip('*')
            
    6.切分split,rsplit(右边开始),lsplit(左边开始)
        以什么分割,返回一个列表
        info = 'dsf:sdf:sdfSDF'
        print(info.split(":"))
        用冒号拼接 只能是字符串
        res = info.split(":")
        print(":".join(res))
        
    7.循环
        msg='hello'
        for i in msg:
        print(i)
        
    8.替换replace
        msg = "sad tt suu"
        print(msg.replace("s","a"))
    
    9、判断是否是纯数字
        msg = '1233334'
        print(msg.isdigit())
    
    10.format
        res = '{} {} {}'.format('apple',23,3)
        print(res)
        res = '{1} {0} {1}'.format(7,9,6)
        print(res)
        res='{a}{b}{c}'.format(a=1,b=2,c=3)
        print(res)
        
    
    
    
五,列表
    类似于字符串
    
    增加
    append  添加在末尾
    insert  根据索引添加
    extend 追加多个
    删除
    del   都可以用
    remove  列表用
    pop   删除后并返回
    
    改
    a[0]=2
    
    查
    in  not in   切片

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值