String Common methods Python

Source: Internet
Author: User

1 bit_length () the minimum number of digits to use when the decimal is in binary notation2# v = -3# data =v.bit_length ()4 # Print (data)5# s ='Abcdefjh'6# S1 = s[0:3]7 # Print (S1)8# s2 = s[5:0:-1]9 # Print (S2)Ten# s3 = s[-1::-2] One # Print (S3) A# a ='everything I never told you' -# a1 =a.capitalize () #首字母大写 - # Print (A1) the# a2 =a.swapcase () #大小写转换 - # Print (A2) -# a3 =a.title () #每个单词首字母大写 - # Print (A3) +# a4 = A.center ( -,"*") #内容居中, (total length, blank padding) - # print (A4) +# A5 = a.count ('e',0, -) #字符串中元素出现的个数. can be sliced A # Print (A5) at#s ='Talk was cheap make the move' -# s2 ="sad\t" -# s3 =S2.expandtabs () - # Print (S3) - #\t in front of the full-complement - # By default, a tab key becomes 8 spaces, if the character in front of the tab is less than 8, then complete 8, if the character in front of the TAB key is more than 8 less than 16, then complete 16, and so on each complement of 8.  in# s ='Talk was cheap make the move' -# S1 = S.startswith ("Tal") #判断是否以 ... Start to # Print (S1) #返回的是布尔值 +# s2 = S.endswith ("Move") #判断是否以 ... End - # Print (S2) the# s3 = S.startswith ("e", One, -) #可切片, Gu Tou disregard butt * # Print (S3) $#s ='Talk was cheap make the move'Panax Notoginseng# S4 = S.find ("cheap",8, the) #寻找字符串中的元素是否存在 -# print (S4) #若存在返回索引值, if there is no return-1 the# S5 = S.index (" Make") #寻找字符串中的元素是否存在 + # Print (S5) #若存在返回索引值, error if not present A# s6 ='Life was short I love python'. Split () the # Print (S6) #以什么分割最终形成一个不含该分割元素的列表, the default element is a space +# s7 ='Life was short I love python'. Split ('I') - # Print (S7) $ # $ #format的三种用法, formatted output -# msg ='my name is {}, this year {}, gender {}'. Format ('Eason', -,'male') - # Print (msg) the# msg ='my name is {}, this year {}, gender {}'. Format ('Eason', -,'male') - # Print (msg)Wuyi# msg ='my name {name}, this year {age}, gender {sex}'. Format (sex='male', name='Eason', age= -) the # Print (msg) - #strip Wu# NAME ='*ea*son**' -# Print (Name.strip ('*') ) #去掉首尾的符号 By default is a space About# Print (Name.lstrip ('*') ) #去掉左 (first) side of the symbol $# Print (Name.rstrip ('*') ) #去掉右 (tail) side of the symbol string in the middle of not falling - #replace -# s ='think of your night, black what can not see, you know not' -# Print (S.replace ('You're','Pig',2) ) #替换 (old, new, left-to-right replacement number) A # # #is系列 +Name ='mark123' the # Print (Name.isalnum ()) #判断字符串由字母或数字组成 - # Print (Name.isalpha ()) #判断字符串只由字母组成 $#print (Name.isdigit ()) #判断字符串只由数字组成 The return value is a Boolean type

String Common methods Python

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.