A string of Python data types (ii)

Source: Internet
Author: User

Continue with 1.isdecimal,isgigit,isnumeric above: whether the current input is a number
1 "  A "

1 v1 = test.isdecimal ()2 v2 = test.isdigit ()3 v3 = test.isnumeric () C10>4Print(v1, v2)
Results:
True True
2.isidentifier: Determine if the identifier is
1 Import keyword 2 Print (Keyword.iskeyword ("def")) 3 " def " 4 v = test.isidentifier ()5print(v)
Results:
Truetrue

3.isprintable: Whether there are non-visible characters
1 # \ t  tab 2#  \ n  line break 3"ddfer\thuyb"  4 v = test.isprintable ()5print(v)

Results:
False

4.isspace: Determine if all spaces are blank
1 " " 2 v = test.isspace ()3print(v)

Results:
True

5.istitle: Determine if the title is
1 " ADSJDJKSDSKD JDFKSDSLKDJ " 2 v1 = test.istitle ()3print(v1)4 v = test.title () 5 Print (v) 6 v2 = test.istitle ()7print(v2)

Results:
FALSEADSJDJKSDSKD Jdfksdslkdjfalse

6.join: Stitching each element in a string according to a specified delimiter
1 " you are the wind, I am the sand " 2 Print (test) 3 ' ' 4 v = t.join (test)5'_'. Join (Test) 6 Print (v) 7 Print (v1)

Results:
You are the wind son I am the sand you are the wind son I am the sand You _ is _ the Wind _ son _ i _ is _ sha

7.ljust,rjust,zfill: Specifying a size padding character for a string
 1  test =  " feng   " 2  v = test.ljust (20, " *  "  )   3  v1 = test.rjust (20, " *   " )  4  v2 = Test.zfill (20 5  print   (v)  6  print   (v1  7  print  (v2) 

Results:
feng********************************Feng0000000000000000feng

8.islower,lower,isupper,upper: Determine if all capitalization and conversion are case-sensitive
1 " Feng " 2 v1 = test.islower ()3 v2 = test.lower ()4print(V1,V2)  5 v3 = test.isupper ()6 v4 = test.upper ()7Print (V3,V4)

Results:
False Fengfalse FENG

9.lstrip,rstrip,strip: Remove left and right blank, \t,\n
1 "  "2 v = test.lstrip ()3 v1 = Test.rstrip ()4 v2 =  Test.strip ()5print(V,V1,V2)

Results:
Feng   Feng Feng

10.translate: convert the corresponding characters
1 " SAEVDDS;GFUIUYV;SDIUJSD " 2 m = Str.maketrans ("aeiou""12345") 3 new_v = v.translate (m)4print(new_v)

Results:
S12vdds;gf535yv;sd35jsd

11.partition,rpartition,split,rsplit: Split by specified character
1Test ="TESTUUFUSKJKSDKD"2v = test.partition ('s')#split up into three points3V1 = test.rpartition ('s')4V2 = Test.split ('s', 2)5V3 = Test.rsplit ('s', 3)6 Print(V, V1, v2, v3)

Results:
('te','s','TUUFUSKJKSDKD') ('TESTUUFUSKJK','s','DKD') ['te','Tuufu','KJKSDKD'] ['te','Tuufu','KJK','DKD']

12.splitlines: Split, only according to, True,false: whether to keep line breaks
1 " WDSDSFD\NSDFDFG\NCADEWEFQ\NSD " 2 v4 = test1.splitlines (True)3print(v4)

Results:
['wdsdsfd\n'sdfdfg\n'cadewefq\ n"sd")

13.startswith,endswith: Start with xxx, end with XX
1 " Backend 1.1.1.1 " 2 v = test.startswith ("a")3print(v) 4 v1 = test.endswith ('a')5print(v1)

Results:
Falsefalse

14.swapcase: Case Conversion
1 " Feng " 2 v = test.swapcase ()3print(v)

Results:
FENG

Well, that's almost all the commonly used string functions

A string of Python data types (ii)

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.