19, python based learning - and string operations

. 1  # ! / Usr / bin / Python the env 
2  # __author: HLC 
. 3  # DATE: 2019/5/26 
. 4  # string is a single quotes' or double quotes "any text enclosed, for example: 'asd'," 123 " 
5  # '" is not part of the string, if necessary as part of the string, plus, in single quotes outside double quotes, such as: "! IT apos a Good" 
. 6  
. 7  # create a string 
. 8  # var1 = "the Hello Word " 
. 9  # var2 = 'Python Book' 
10  
. 11  # string operations 
12  # repeatedly output string 
13 is  # Print (" Hello "* 2) #hellohello 
14  # by the index acquiring the character string 
15  # Print ("hello"[2:]) # llo
16  # Analyzing members 
. 17  # Print ( "of He" in "Hello") # True 
18 is  # Print ( "HE1" in "Hello") # False 
. 19  # formatted string 
20 is  # name = "ASD" 
21 is  # Print ( " % S IS name your! "% name) #your name IS ASD! 
22 is  # string concatenation 
23 is  # A =" QWE " 
24  # B =" 456 " 
25  # C =" UIO " 
26 is  # Print (A + B) # qwe456, using the "+" splicing, inefficient 
27  #
 28  # Print ( ''. the Join ((A, B, C))) # qwe456uio,High efficiency 
29  #Print ( '------'. the Join ((A, B, C))) ------ 456 ------ # QWE UIO 
30  
31 is  # built-in method string 
32 # ST = " Hello Kitty " 
33 is  # Print (st.count ( "L")) # 2, counting the number of elements 
34 is  # Print (st.capitalize ()) # the Hello Kitty, initials 
35  # Print (st.center (20 is , "#")) # contents center, the other is filled with the specified character 
36  # Print (st.endswith ( "TTY")) # True, the content is determined to end a 
37 [  # Print (st.startswith ( "Hell") ) # True, in order to determine the beginning of the contents of a 
38  # ST = "of He \ tllo Kitty" 
39  # Print (st.expandtabs (20)) # of He the LLO Kitty,The \ t is replaced with designated spaces 
40  #print (st.find ( "t") ) # 8, to find the first element, and the index value is returned, there is no return -1 
41 is  # ST = "Hello Kitty NUM} {} {SAM" 
42 is  # Print (ST .format (sam = 100, num = 200)) # hello kitty 100 200, formatted output 
43 is  # Print (st.format_map ({ "NUM": 100, "SAM": 200 is})) # 200 is 100 Hello Kitty, formatted output 
44 is  # Print (st.index ( "T")) #. 8, the first element to locate and return the index value, and compared to find, without being given 
45  # Print (st.isalnum ()) False # determines whether strings, numbers, characters 
46 is  # Print (st.isalnum ()) # determines whether or False strings, numbers, characters 
47  # Print (st.isdecimal ()) is determined for the decimal False # 
48  # print ( "1234" .isdigit () ) # True determines whether an integer of 
49  #print ( "123.4" .isdigit () ) # False determines whether the whole word 
50  # Print ( "123.4" .isnumeric ()) # False is determined whether the same for the whole word, and isdigit function 
51 is  # Print ( "Asd" .islower ()) # False determine whether all lowercase 
52  # Print ( "Asd" .isupper ()) # False determine whether all uppercase 
53  # Print ( "" .isspace ()) # True determine whether a space 
54  # Print ( "Asd Tre" .istitle ()) # True determines whether the title, first letter capitalized 
55  # A = "ADS" 
56 is  # B = "456" 
57 is  # Print ( "." the Join ((A, B))) # ads456 string concatenation, high efficiency 
58  # Print ( "Asd Tre."upper ()) # ASD TRE uppercase 
59  # Print ( "Asd Tre" .swapcase ()) # asd Tre-sensitive inversion 
60 # Print ( "Asd Tre" .ljust (20 is, "#")) # Asd Tre #############, right filling 
61 is  # Print ( "Asd Tre" .rjust (20 is, "#")) # ############# Asd Tre, left filling 
62 is  # ( "\ tAsd Tre \ n-" .strip ()) Print # Asd Tre, remove the front or rear space, line, tab 
63 is  # Print ( "\ tAsd Tre \ n-" .lstrip ()) # Asd Tre, remove the front spaces, line breaks, tabs 
64  # Print ( "\ tAsd Tre \ n-" .rstrip ()) # Asd Tre, remove trailing spaces, line breaks, tabs 
65  # Print ( "Asd Tre" .replace ( "Tre", "789")) Asd # 789, the replacement string 
66  # Print ( "Asd Tre Tre ".replace (" Tre " ," 789 ", 1)) # Asd 789 Tre, replacement string, replace 1 
67  # Print ("Aesd Tre ".rfind (" e " )) # 7, from right to left to find 
68  #print ( 'Asd Tre asdfk'.split (' ')) # [' Asd ',' Tre ',' asdfk '] is separated by a space objects 
69  # Print (' Asd Tre asdfk'.split ( 'S')) # [ 'A', 'd Tre a', 'dfk'] to "s" is separated by the object 
70  # Print ( 'Asd Tre asdfk'.split (' S ',. 1)) # [' A ',' D Tre asdfk '] to "s" is separated by the object, starting from the left 1st division 
71 is  # Print (' Asd Tre asdfk'.rsplit ( 'S', 1)) # [ 'Asd Tre A', 'DFK'] to "s" is separated by the object 1 from the right division 
72  # Print ( 'ASD Tre asdfk'.title ()) # Asd Tre Asdfk, first letter capitalized

 

Guess you like

Origin www.cnblogs.com/hlc-123/p/10926642.html