zoukankan      html  css  js  c++  java
  • 数据类型一

                     数据类型(一)

    一、数据类型

    1、数字

    2、字符串

    3、列表

    4、字典

    5、元组

    6、集合

    二、数字的应用 数字是不可变类型的变量

    三、字符串的应用

    (1)字符串的查找

     l='egon' print(l[2]) 
    
          >>>o for i in l 
    
         print(i,end=' ')
    
          >>>e g o n 

       字符串也是不可变的

    (2)字符串的内置方法

       1、移除空白

    strip l='   egon   ' print(l.strip()) 

        lstrip 移除左边的空白 rstrip 移除右边的空白

       2、split 切分

     l='egon say hellos' print(l.split())

      默认以空格切分

    l='egon|say|hello|hay' 
    
     print(l.split('|'))

       切分一次

    msg='download|xhp.mp4|3000'
    
    print(msg.split('|',1)) msg_0=msg.split('|',1)
    
    例: print('命令是%s,命令的参数是%s' %(msg_0[0],msg_0[1]))

    长度  索引

    len l='hello world' print(len(l))
    print(l[1:3])

    startswith,endswith 的用法

    l='alex_hello'
    
    print(l.startswith('alex'))
    print(l.endswith('hello'))


    replace的用法

    name='alex say :i have one tesla,my name is alex'
    
    print(name.replace('alex','egon',1))

    替换%和format

    print('my name is %s,my age is %s,my sex is %s.' %('egon',20,'male'))
    
    print('my name is {},my age is {},my sex is {}.'.format('egon',20,'male')) 
    
    print('my name is {0},my age is {1},my sex is {2}.'.format('egon',20,'male'))
    
    print('my name is {name},my age is {age},my sex is {sex}'.format('name='egon',age=20,sex='male'))


    find 、index的区别

    name='egon say hello' print(name.find('s',1,3))  #顾头不顾尾,找不到会返回-1,
    
    print(name.index('a'))不会报错,找到了显示索引 print(name.index('a'))  #同上,但是找不到会报错


    count的用法

    print(name.count('l',1,5))  #顾头不顾尾,不指定范围会查找所有

    join 的作用

    l='egon say hellos'
    
    print(l.split()) l1=l.split()
    
    print(':'.join(l1))

    lower,upper 的用法

    name ='egGon'
    
    print(name.lower()) 
    
    print(name.upper())

    expandtabs 的用法

    name='egon	hello' 
    
    print(name) print(name.exoandtabs(1))  #expangtabs代表空格键
  • 相关阅读:
    script标签加载顺序(defer & async)
    nginx反向代理vue访问时浏览器加载失败,出现 ERR_CONTENT_LENGTH_MISMATCH 问题
    Git每次进入都需要输入用户名和密码的问题解决
    update select
    sql --- where concat
    GO -- 正则表达式
    浏览器中回车(Enter)和刷新的区别是什么?[转载]
    转: Linux --- Supervisor的作用与配置
    Golang 使用Map构建Set类型的实现方法
    linux -- 查看应用启动时间
  • 原文地址:https://www.cnblogs.com/hzauq/p/7234783.html
Copyright © 2011-2022 走看看