#字符串操作 #定义字符串 A = "Let's Go" #字符串切片 print ("HelloWorld" [2:]) #通过索引获取字符串中的字符, and list slices similarly #关键字 in PRI NT ("Llo" in "HelloWorld") #返回TRUE或False #字符串拼接 #可以用 + stitching string #join实现拼接 a = "123" b = "456" D = "789" c= ' * * * '. Join ([a,b,d]) #用 * Stitching a,b,c #返回123 ***456***789 #% formatted output string print (' There is s ome examples ') print ('%s is some examples '% ' there ') #字符串的内置方法 st = "Hello Kitty{name}" St.count ("T") #统计t的个数 st.capitalize #首字母大写 St.center (50. " # ") #居中 st.endswith (' ty ') #以某个内容结尾 st.startswith (' he ') #以某个内容开头 st.expandtabs (tabsize =) #修改缩进 st.find (' t ') #寻找, returns the index value St.format (name = "haha") #格式化输出的另一种方式 print (St.index (' t ')) #返回t的索引值 print (' My tltle '. Lower ()) #将字符串里 The letters are all converted to lowercase print (' My Tltle '. Upper ()) #将字符串里的字母全部转换为大写 print (' \tmy tltle\n '. Strip ()) #将字符串里不显示的内容去掉 print (' My titl E title '. Replace (' itle ', ' lesson ', 1)) #替换, replace (' substituted value ', ' replace content ', 1 (replace several)) print (' My title TiTle '. Split (' I ', 1)) #分割, Split (' Split value ', split count)
"Python"--string