Common operations for python-strings

Source: Internet
Author: User

1Name ="My name is Irving and I am years old!"2 3 #开头字母大写4 print (Name.capitalize ())5 6 #统计某字符个数7Print (Name.count ("I"))8 9#把字符串延长至50字节, and centered, insufficient "--"CompleteTenPrint (Name.center ( -,"-")) One  A#检查是否以 "LD"End -Print (Name.endswith ("LD")) -  the #修改tab为30字节 -Name ="my \tname is Irving and I am years old!" -Print (Name.expandtabs (tabsize= -)) -  + #查找name的位置 -Print (name.Find("name")) +Print (Name[name.Find("name"):]) A  at #format, Placeholder -Name ="My name is {name} and I am {age} years old!" -Print (Name.format (name='Irving', age= at)) -Print (Name.format_map ({"name":"Irving"," Age": at})) #format_map dictionary form -  - #判断字符串是否为整数类型 inPrint'ba123'. IsDigit ()) -  to #判断字符串是否为字母 +Print'ABa'. Isalpha ()) -  the #判断是否为十进制数字 *Print'1 A'. Isdecimal ()) $ Panax Notoginseng #判断是否为数字和字母组合 -Print"ads1". Isalnum ()) the  + #判断是否为一个合法的标识符 (variable name) APrint'a [email protected]'. Isidentifier ()) the  + #判断字符串是否为标题 -Print'Ti Io Ee'. Istitle ()) $  $ #判断是否可以打印 -Print'Asdw Iu'. Isprintable ()) -  the #判断字符串是否为大写 -Print'AAAA'. Isupper ())Wuyi  the#Jointo insert an element between the elements -Print'-'.Join(['1','2','3'])) Wu 1-2-3 -  About #从左边开始算, not enough for 50-length ' # ' $Print (Name.ljust ( -,'#')) -Print (Name.rjust ( -,'#')) -  - #把字符串全部换成小写 APrint'xasss'. Lower ()) +  the #把字符串全部换成大写 -Print'Asdw'. Upper ()) $  the#忽略左边的'/ N' thePrint'n\irving'. Lstrip ()) thePrint'irving\n'. Lstrip ()) the  - #忽略全部 \ n inPrint'\nirving\n'. Strip) the  the #翻译对应字符, the number is equal before and after Aboutp = Str.maketrans ("Irving","123456") thePrint"Irving". Translate (p)) the  the #定义步长替换 +Print'Hihihi'. replace ('H','h',2)) -  the location of #从左边开始寻找第一个 ' I 'BayiPrint'Hihihihihi'. RFind ('I')) the  the #指定分隔符 -Print'1+2+3+4'.Split('2')) -  the #用 ' \ n ' Split thePrint'1+2\n+3+4'. Splitliness ()) the  the #大小写互换 -Print'Irving'. Swapcase ()) the  the #字符串转换成标题 thePrint'im AA'. Title ())

Common operations for python-strings

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.