• DAY5基本类型


    1,strip:去除,lstrip:left strip 的简写,rstrip:right strip.

    name='33app3333'             ----app
    print(name.strip('3')) ----app
    print(name.lstrip('3')) ----app3333
    print(name.rstrip('3')) ----33app
    2,startswith,endswith.(ˇˍˇ) 表示开始带着什么
    name='wahda'
    print(name.startswith('w'))-----True
    print(name.dendswith('w'))----wrong
    print(name.startswith('a'))----True
    3,replace代替
    name='alex says:my name is alex'
    print(name.replace('alex','sb',1))----sb says:my name is alex.
    4,format,表示规定什么格式
    res='{}{}{}'.format('alex','is','18')---alex is 18
    res='{0}{1}{0}'.format('alex','is',''18)---alex is alex
    res='{name}{age}{add}'.format(name='panyu',add='where',age=18)---panyu 18 where
    5,find,index,count.
    res='hello,you have any body'
    print(res.find('o'),1,10)---4 find函数里的字符,第一是字母,第二和第三个数字是指从第几个位置到第几个位置,最后显示出来的是从第一个数字的位置到第二个位置里找前面字母出现的位置。
    如果出现了,把字母的位置显示出出来,如果在这区间里面没有,就直接显示-1(在这区间里面没有)
    print(res.index('o',1,10))---4 index和find函数的字符意思是一样的,只不过在区间没找到字符位置的时候,系统会直接显示错误,后面就不会运行。
    print(res.count('o',1,10))----2 首先结果显示的前面字符“o”在后面数字区间中显示的次数。如果没有的话会显示0.
    6,split,
    name=c://sda:/sd
    print(name.split('/'))-----'c:', '','sda:' '',sd'
    print(name.split(':',1))----'c' ''//sda:/sd----这里指把第一:改变成空格键。
    print(name.rsplit(:),1))----这个就是从右边开始,把第一个改成空格键。
    7,join把什么东西加进字符串中间
    tag=" "
    print(tag.join('hello,world'))---h e l l o w o r l d
    print(tag.join(['hello','world']))---hello world上面是吧每个单词作为字符,这里是列表,所以把整个hello作为整体。
    8,center把字符串放中间,在机上一定数量的符号,ljust把字符串放左边,在右边加上一定数量的符号,zfill数量少的时候用0填充。
    name='panyu'
    print(name.center(10,"q"))----qqpanyuqqq
    print(name.ljust(10,'q'))-----panyuqqqqq
    print(name.zfill(10))-----00000panyu
    9
    #expandtabs
    name='egon	hello'
    print(name)
    print(name.expandtabs(1))
    
    #lower,upper
    name='egon'
    print(name.lower())
    print(name.upper())
    
    
    #captalize,swapcase,title
    print(name.capitalize()) #首字母大写
    print(name.swapcase()) #大小写翻转
    msg='egon say hi'
    print(msg.title()) #每个单词的首字母大写
    
    #is数字系列
    #在python3中
    num1=b'4' #bytes
    num2=u'4' #unicode,python3中无需加u就是unicode
    num3='四' #中文数字
    num4='Ⅳ' #罗马数字
    
    #isdigt:bytes,unicode
    print(num1.isdigit()) #True
    print(num2.isdigit()) #True
    print(num3.isdigit()) #False
    print(num4.isdigit()) #False
    
    
    #isdecimal:uncicode
    #bytes类型无isdecimal方法
    print(num2.isdecimal()) #True
    print(num3.isdecimal()) #False
    print(num4.isdecimal()) #False
    
    #isnumberic:unicode,中文数字,罗马数字
    #bytes类型无isnumberic方法
    print(num2.isnumeric()) #True
    print(num3.isnumeric()) #True
    print(num4.isnumeric()) #True
    
    
    #三者不能判断浮点数
    num5='4.3'
    print(num5.isdigit()) 
    print(num5.isdecimal())
    print(num5.isnumeric())
    '''
    总结:
        最常用的是isdigit,可以判断bytes和unicode类型,这也是最常见的数字应用场景
        如果要判断中文数字或罗马数字,则需要用到isnumeric
    '''
    
    #is其他
    print('===>')
    name='egon123'
    print(name.isalnum()) #字符串由字母和数字组成
    print(name.isalpha()) #字符串只由字母组成
    
    print(name.isidentifier())
    print(name.islower())
    print(name.isupper())
    print(name.isspace())
    print(name.istitle())


  • 相关阅读:
    VS2012 for SharePoint2013 Tool安装
    SharePoint 2013网站管理网站策略(关闭和删除策略)
    呼风唤雨的公交
    ASP、Access、80040e14、保留关键字、INSERT INTO 语句的语法错误
    表格边框设置
    DotNet开发中关于SQLServer连接的两种方法之比较
    SQL语句集锦
    动态网页设计笔记
    SQL SERVER中日期 where 问题的解决
    配置你的ASP.NET运行环境
  • 原文地址:https://www.cnblogs.com/52forjie/p/7197378.html
Copyright © 2020-2023  润新知