zoukankan      html  css  js  c++  java
  • day02_字符串的内置方法

    String的内置方法

    st='hello kitty {name} is {age}'
    
    print(st.count('l'))       #  统计元素个数
    print(st.capitalize())     #  首字母大写
    print(st.center(50,'#'))   #  居中
    print(st.endswith('tty3')) #  判断是否以某个内容结尾
    print(st.startswith('he')) #  判断是否以某个内容开头
    print(st.expandtabs(tabsize=20))
    print(st.find('t'))        #  查找到第一个元素,并将索引值返回
    print(st.format(name='alex',age=37))  # 格式化输出的另一种方式   待定:?:{}
    print(st.format_map({'name':'alex','age':22}))
    print(st.index('t'))
    print('asd'.isalnum())
    print('12632178'.isdecimal())
    print('1269999.uuuu'.isnumeric())
    print('abc'.isidentifier())
    print('Abc'.islower())
    print('ABC'.isupper())
    print('  e'.isspace())
    print('My title'.istitle())
    print('My tLtle'.lower())
    print('My tLtle'.upper())
    print('My tLtle'.swapcase())
    print('My tLtle'.ljust(50,'*'))
    print('My tLtle'.rjust(50,'*'))
    print('	My tLtle
    '.strip())
    print('	My tLtle
    '.lstrip())
    print('	My tLtle
    '.rstrip())
    print('ok')
    print('My title title'.replace('itle','lesson',1))
    print('My title title'.rfind('t'))
    print('My title title'.split('i',1))
    print('My title title'.title())
    

    摘一些重要的字符串方法

    print(st.count('l'))
    print(st.center(50,'#'))   #  居中
    print(st.startswith('he')) #  判断是否以某个内容开头
    print(st.find('t'))
    print(st.format(name='alex',age=37))  # 格式化输出的另一种方式   待定:?:{}
    print('My tLtle'.lower())
    print('My tLtle'.upper())
    print('	My tLtle
    '.strip())
    print('My title title'.replace('itle','lesson',1))
    print('My title title'.split('i',1))
    
  • 相关阅读:
    shell脚本修改Linux系统中所有IP样例
    关闭并卸载数据库脚本
    查询编译不通过的存储过程并重新编译
    SQL函数造数据样例(一)
    类型转换和多态
    Java学习笔记(三)
    Java学习笔记二()
    Java学习笔记(一)
    1.2.零宽断言
    1.3.匹配小括号的字符(可能有小括号在一行的,也有多行的)
  • 原文地址:https://www.cnblogs.com/lihuafeng/p/14026176.html
Copyright © 2011-2022 走看看