"Python"--string

Source: Internet
Author: User

#字符串操作 #定义字符串 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.