重复输出字符:print('hello'*2)git
经过索引获取字符串字符:print('hello'[2:])api
判断串1是否在串2,3,4中:print(123 in [234,456,678])
ide
格式字符串:print('%s%s%'infor[name],infor[addr])spa
字符串拼接:c=' '.join([a,b])索引
st.count('元素') //字符串元素的个数ip
st.capitalize() //首字母大写ci
st.center(50,'_') //50个"_"打印出来,而且将字符串放到中间字符串
st.endswith('x') //判断以什么结尾,返回布尔值it
st.startwith(' ') //判断以某个内容开头,返回布尔值技巧
st.expandtabs(tabsize=20) st=he\tllo //e和t中间有tabsize个空格
st.find('t') //查找到第一个t,并将索引值返回
st.fotmat_map({'name':'alex','age':23}) //返回字符串中{name}{age}
st.index('t') //同find,字符串中如t,find方法会报错,而index则返回-1
st.isalnum() //是否包含数字或字母
st.isdecimal() //判断是否为十进制的数
st.isdigit() //判断是否为数字
st.isidentifier() //判断是否为非法字符
st.islower()/isupper //判断是否为全小写/全大写
st.isspace() //判断是否为空格
st.istitle() //判断是否为标题格式,首字母大写
st.lower()/upper() //转化为大写或者小写
st.swapcase() //大小写反转
st.ljust(50,'*') //字符串只靠左
st.strip()/lstrip()/rstrip() //开头或结尾去掉空格或\n
st.replace('a','b') //把a替换成b
st.rfind('t') //从右向左走首个t的真实索引位置
st.split(' ',1) //用某些字符分割,且分割1次