Python---string

Source: Internet
Author: User


test =  "My name is fengxiaoli" # # #确定字符串中字符位置print (Test.rfind ("M"))                     #找到m所在的位置, The rightmost print (Test.find ("name"))                   #找到字符串中name的开头位置, this is 3print (Test[0:test.find ("name"))           #字符串切片, from 0 to the beginning of the name 3## #字符串补齐print (Test.center (), "-")                 #给定字符串长度50, less than 50 add-to-complement print (Test.ljust ("*"))                  #给定字符串长度50, less than 50 added * padded print (Test.rjust ( "-")                 #给定字符串长度50, Less than 50 added * padded          #字符串判断print ("12ADFAAGDADF". Isalnum ())             #判断是否是英文字母和数字, is the return Tureprint ("AAf". Isalpha ())                      #判断是否是英文字符串print ("IsDigit")                      # Determines whether it is an integer print ("ADFADF". Isidentifier ())            # Determines whether a valid identifier (variable) is print (" ". Isspace ())                        #判断是否是一个空格print (" my name is". Istitle ())             #判断是否是一个标题print ("Ni hao". Isupper ())                 # Determines whether the string is uppercase print (Test.endswith ("Li"))                  #判断字符串是否由li结尾, is to return to TureprinT (Test.startswith ("my"))              ## String conversion print ("ASDF". Lower ())                            #将大写转化为小写print ("Sdafa". Upper ())                            #将小写转化为大写print ("Asdfadadfaad". Swapcase ())                 #大小写互换print (" my name is". Title ())                     #将其转化为titleprint ( Test.expandtabs (tabsize=30))             # Converts the TAB key (\ t) in a string to 30 spaces print (" my name is ". Replace ("M", "M", 1))         #将m替换成大写的M, replace only 1 # output:my name is# go to the beginning end of the space and line break print ("    \nmy name is is". Strip ())              #去掉开头结尾的空格和换行符print ("fnegxiaoli\n". Rstrip ())                    #去掉右边的空格和换行符print ("    \nfnegxiaoli\n ". Lstrip ())               #去掉左边的空格和换行符 # string Split  print ("Adf+na +df". Split ("+"))                    #指定分隔符分割字符串print ("ADD\NADF\NADFG". Splitlines ())             #按换行符分割 # Convert the list to string print ("+". Join (["1", "2", "3" ]))                  # The following list is separated by the + number and converted to a string # Supplement: P = str.maketrans ("abcdef", "123456")             &nbsp, #将abcdef与123456对应print ("Fengxiaoli". Translate (p))                   #然后fengxiaoli中有属于abcdef字母的用与之对应的数字替换 # Output:65ngxi1olitest1 =  "My name is {_name} ,age is {_age}" Print (Test1.format (_name= "Fengxiaoli", _age=24 ))       #格式化输出print (Test.capitalize ())                          # Capitalize the first letter of the string print (Test.count ("M"))                             #统计字符串中m的个数


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.