zoukankan      html  css  js  c++  java
  • 字符串操作

    name = 'His name is Louie'

    print(name.captitalize()) #首字母大写

    print(name.count("i")) #i的数量

    print(name.ceter(50,“-”) # 打印50个-

    print(name.endswith("ie") #判断string以什么结尾

    print(name.expandtabs(tabsize=10) #配合string中加“”打印多少个空格 name = 'His name is Louie'

    print(name.find(“n”)

    print(name.format(name='Alex', year=23))  #name = “His name is {name} and i am{year} old”

    print(‘ab23’.isalnum()) #包括数字和字母

    isalpha() #纯英文字符

    isdecimal() #十进制

    isdigit() #整数判断

    isidentifier() #判断合法的变量名或者标识符

    islower() #小写

    isspace()

    print("My Name Is".istitle())#每个字符第一个是大写

    isprintable() #不能打印的文件,tty file

    isupper() #大写

    print("Name", join("==")

    print('+'.join(['1','2','3','4']))

    ljust(50,'*')  #长度50不够,*补上

    rjust(50,'+')

    lower()

    upper()

    print(' Alex'.lstrip()) #去左边的空格和回车

    print(' Alex '.rstrip()) 

    print('      Alex '.strip())

    #数字对应传递maketrans的方法,密码传递作用

    p = str.maketrans("abcdef","123456")

    print("Today is Python day!".translate(p))

    print("Today is Python day!".replace("i","I",1))

    print("Today is Python day!".rfind('i') #最右边的值的index

    print("Today is Python day!".split()) #字符串分隔

    print("1+2+3+4".split(“+”))

    splitlines()

    startswith()

    endswith()

    swapcase()

    print("Today is Python day!".zfill(50)) #十六进制的补位用法

  • 相关阅读:
    禁止用户打开HTML页面调试
    Git 忽略提交 .gitignore
    PHP日期时间处理
    HTML页面中JavaScript能获取到的各种屏幕大小信息
    移动浏览器H5页面通过scheme打开本地应用
    Python爬虫利器:Beautiful Soup
    MySQL分页查询优化
    JavaScrpit中异步请求Ajax实现
    PHP反射机制
    CentOS下nginx php mysql 环境搭建
  • 原文地址:https://www.cnblogs.com/ywyin/p/8988043.html
Copyright © 2011-2022 走看看