#_*_coding:utf-8_*_#作者:王佃元#日期:2019/12/9#string操作print('hello'*2) #乘法操作,输出对应次数print('helloworld'[2:]) #切片操作,跟列表操作一致print('w' in 'helloworld') #判断内容是否在另一个内容里面print('%s is a good teacher'%('dery')) #格式化输出a = '123'b = 'abc'c = a + bc = ''.join([a,b,c])print(c)#字符串的内置方法st = 'hello kitty is {name} is {age}'#c 开头的方法print(st.count('l')) #计算某个内容出现的次数print(st.capitalize()) #首字母大写print(st.center(50,'*')) #居中#e 开头的方法print(st.endswith('ty')) #判断字符串已某个内容结尾,返回bool值print(st.startswith('www')) #判断字符串已某个内容开头,返回bool值print(st.expandtabs(tabsize=10)) #较少使用,扩展一个tab键代表几个空格,需要在增加tab键的地方增加\t#f 开头的方法print(st.find('t')) #查找第一个元素,并返回索引值print(st.format(name = 'dery',age = 20))print(st.format_map({'name':'dery','age':20})) #格式化输出,在字符串中需要使用{}将要格式化输出的内容包起来#i 开头的方法print(st.index("t")) #返回字符对应的索引,无对应内容返回-1print(st.isdigit()) #返回一个bool值,判断是不是一个整数,例如120.236是不可以的print(st.isalnum()) #print(st.isdecimal()) #判断是不是10进制数print(st.isidentifier()) #print(st.islower()) #判断是不是全小写print(st.isupper()) #判断是不是全大写print(st.isspace()) #判断是不是一个空格print(st.istitle()) #所有单词首字母大写,判断是不是一个标题print(st.swapcase()) #大小写反转print(st.ljust(50,'*'))print(st.rjust(50,'*'))print(st.strip()) #去除字符串前后空白字符(空格)print(st.lstrip())print(st.rstrip())print(st.replace('age','name'))print(st.rfind('t')) #右边数第一个出现的t的位置print(st.split(" ")) #分割作用,将字符串按照给定的内容进行分割,获得列表print(st.split('i'))print(st.title()) #将字符串变为标题格式
来源:https://www.cnblogs.com/python-beginner/p/12013237.html