#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Huanglinsheng # name.capitalize() 首字母大写 # name.casefold() 大写全部变小写 # name.center(50,"-") 输出 '---------------------Alex Li----------------------' # name.count('lex') 统计 lex出现次数 # name.encode() 将字符串编码成bytes格式 # name.endswith("Li") 判断字符串是否以 Li结尾"Alex Li".expandtabs(10) 输出'Alex Li', 将 转换成多长的空格 # name.find('A') 查找A,找到返回其索引, 找不到返回-1 '''format''' ''' msg = "my name is {},my age is {}" msg.format("hls",22) print(msg.format("hls",22)) msg = "my name is {1},my age is {0}" msg.format("hls",22) print(msg.format("hls",22)) msg = "my name is {name},my age is {age}" msg.format(name="hls",age=22) print(msg.format(name="hls",age=22)) msg = "my name is {},my age is {}" msg.format_map({'name':'alex','age':22}) ''' # msg.index('a') 返回a所在字符串的索引 # '9aA'.isalnum() True # # '9'.isdigit() 是否整数 # name.isnumeric # name.isprintable # name.isspace # name.istitle # name.isupper # "|".join(['alex','jack','rain']) # 'alex|jack|rain' #字符替换 intab = "aeiou" outtab = "12345" trantab = str.maketrans(intab,outtab) str = "this is string example....wow!!!" str.translate(trantab) print(str.translate(trantab)) #msg.swapcase 大小写互换