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()) 用来判断变量名是否可用

  • 相关阅读:
    111
    关于Node.js中安装完express后不能使用express命令
    vscode tab转空格
    【终端使用】rm命令,删除文件获目录
    WebStorage是什么?
    Vue路由传参
    --save 和 --save-dev的区别
    第五篇,理解JS模块化编程思想
    第四篇,JavaScript面试题汇总
    第三篇,ajax 和 axios、fetch的区别
  • 原文地址:https://www.cnblogs.com/bailongcaptain/p/12458203.html
Copyright © 2011-2022 走看看