zoukankan      html  css  js  c++  java
  • str内部方法

    代码

    #str内部功能
    name='  aK am	il.L	iu'
    age=18
    num=-11
    ab='#'
    ac=('1','2','3','4','5','6','7')
    print(dir(name))
    print(name.capitalize())#capitalize(self):首字母大写
    print(name.center(30,'#'))#center(self, width, fillchar=None): 内容居中,width:总长度;fillchar:空白处填充内容,默认无
    print(name.count('i'))#count(self, sub, start=None, end=None):子序列个数
    '''
    decode(self, encoding=None, errors=None):解码
    encode(self, encoding=None, errors=None):编码,针对unicode
    '''
    print(name.endswith('u'))#endswith(self, suffix, start=None, end=None):是否以xxx结束 startswith(self, prefix, start=None, end=None):是否起始
    print(name)
    print(name.expandtabs(3))#expandtabs(self, tabsize=None):将tab转换成空格,默认一个tab转换成8个空格
    print(name.find('i'))#find(self, sub, start=None, end=None):寻找子序列位置,如果没找到,返回 –1
    print(name.find('b'))
    #format(*args, **kwargs):字符串格式化,动态参数,讲函数式编程时细说
    print(name.index('il'))#index(self, sub, start=None, end=None): 子序列位置,如果没找到,报错
    print(name.isalnum())#
    '''
    isalnum(self): 是否是字母和数字
    isalpha(self):是否是字母
    isdigit(self):是否是数字
    islower(self): 是否小写
    translate(self, table, deletechars=None):转换,需要先做一个对应表,最后一个表示删除字符集合
    '''
    print(ab.join(ac))#join(self, iterable):连接
    print(name.ljust(30,'$'))#ljust(self, width, fillchar=None):内容左对齐,右侧填充    zfill(self, width):方法返回指定长度的字符串,原字符串右对齐,前面填充0。
    print(name.lower())#lower(self):变小写     swapcase(self):大写变小写,小写变大写
    print(name.lstrip())#lstrip(self, chars=None):移除左侧空白      strip(self, chars=None):移除两端空白
    print(name.partition('m'))#partition(self, sep):分割,前,中,后三部分
    print(name.replace('am', 'qqqqqq'))#replace(self, old, new, count=None):替换
    print(name.split())#split(self, sep=None, maxsplit=None):分割, maxsplit最多分割几次
    print(name.splitlines())#splitlines(self, keepends=False):根据换行分割
    

     结果

    ['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
      ak am	il.l	iu
    #######  aK am	il.L	iu########
    2
    True
      aK am	il.L	iu
      aK am  il.L  iu
    8
    -1
    8
    False
    1#2#3#4#5#6#7
      aK am	il.L	iu$$$$$$$$$$$$$$$
      ak am	il.l	iu
    aK am	il.L	iu
    ('  aK a', 'm', '	il.L	iu')
      aK qqqqqq	il.L	iu
    ['aK', 'am', 'il.L', 'iu']
    ['  aK am	il.L	iu']
    

     

    公众号请关注:侠之大者
  • 相关阅读:
    核函数基础一简单解释
    矩阵的基本性质 之 正规矩阵,矩阵的迹,行列式,伴随矩阵,矩阵的逆,对角矩阵,矩阵求导
    矩阵的基本性质 之 对称矩阵,Hermite矩阵,正交矩阵,酉矩阵
    矩阵的基本性质 之 矩阵加减法,数乘,乘法,转置
    机器学习实战基础(二十七):sklearn中的降维算法PCA和SVD(八)PCA对手写数字数据集的降维
    拉格朗日对偶性
    批处理符号2
    批处理符号1
    set命令
    goto命令
  • 原文地址:https://www.cnblogs.com/kamil/p/5160990.html
Copyright © 2011-2022 走看看