zoukankan      html  css  js  c++  java
  • 字符串之不常用方法

    find.rfind,index,rindex,count
    作用:找到起始索引
    msg='hello world'
    msg.find('e') ----->1
    rfind(反方向)
    ps:index与rindex的用法与find类似,但是若找不到时,find返回-1,index会异常

    conut
    用法:统计
    msg='abc qwe abc abc'
    msg.count('abc') ----->3

    2.center,ljust,rjust,zfill
    用法:
    'abc'.center(10,'') 将abc居中两侧用补齐至10
    'abc'.ljust(10,'') 将abc左对齐右侧用补齐至10
    'abc'.rjust(10,'') 将abc右对齐左侧用补齐至10
    'abc'.zfill(10,'*') 右对齐用0补齐至10

    3.expandtabs
    用法:设置制表符代表的空格
    msg='hello world'
    msg.expandtabs(2) ----->hello world

    4.captalize,swapcase,title
    msg='hello world'
    msg.captalize() ----->Hello world 首字母大写
    msg.swapcase() ----->HELLO WORLD 反转大小写
    msg.title() ----->Hello World 每个单词首字母大写

    islower print('abc'.islower()) True 判断是否全部小写
    isupper print('ABC'.isupper()) True 判断是否全部大写
    istitle print('Hello World'.istitle()) True 判断每个单词首字母是否大写
    isalnum print('123123aadsf'.isalnum()) True 判断是否由字母和数字组成
    isalpha print('ad'.isalpha()) True 判断字符串是否由纯字母组成
    isspace print(' '.isspace()) True 判断是否由空格组成
    isidentifier print('print'.isidentifier()) 用来判断变量名是否可用

  • 相关阅读:
    业余爱好很有必要
    平和的心态
    合理预期
    有所为,有所不为
    iOS中使用UITextView设置不同文本部分点击事件小结
    一直在路上
    Windows平台交叉编译Arm Linux平台的QT5.7库
    UOS创建开机自启程序或脚本
    HTTP HTTP请求报文和响应报文的格式
    ObjectObject.prototype.toString.call()方法的使用
  • 原文地址:https://www.cnblogs.com/bailongcaptain/p/12458203.html
Copyright © 2011-2022 走看看