字符串
基本的操作
a = 'helle',b = 'world'
'hello'*2#两遍hello
'helloworld'[2:] #结果为lloworld
'el' in 'hello' #在,True
c = a+b #字符串的连接,但是更推荐用join
String的常用内置方法:
c = 'hello world {name}'
'--'.join([a,b]) #用--连接字符串ab
c.count('e') #计算e出现次数
c.center(20,'*') #居中,************hello world**************
c.startswith('he') #判断c是否以he开头
c.endswith('aaa')#判断是否以aaa结尾
c.find('t') #查找首个t位置,若存在,则返回索引值,否则返回-1
c.format(name = 'aintdone') #hello world aintdone
c.format_map({'name':'axe'})#()里用字典
c.lower()
c.upper()
c.replace('helle','fuck',1) #c变为fuck world {name}
c.spilt(' ') #分割字符串为列表,''.join()可以将列表变为字符串
c.strip() #去掉字符串开头与结尾的空格,换行符等