Python has five data types, namely: You can view data types using the type built-in function
1:str (String) 2:int (integer) 3:float (floating-point)
3:list (list) 4:dict (dictionary) 5:set (collection)
STR (string) is an immutable type: Each variable corresponds to the value of the data and variable names in the memory is actually associated with, when the value of B is actually opened in memory in a new space, the B point to the new space, and did not directly change the data of the memory space that the B originally pointed to:
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/8E/DE/wKiom1jN7z7yRbBQAAAee9u2foA276.png "title=" Python immutable type. png "width=" "height=" 432 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:700px;height:432px; "alt=" Wkiom1jn7z7yrbbqaaaee9u2foa276.png "/>
Python has a number of methods built into each data type, and the flexibility to use these methods can reduce our code volume a lot, so I'll show you some common methods for strings:
Str.replace ()//String substitution
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/8E/DF/wKiom1jN-KWyvvYrAAAeHIDbjp8865.png "title=" K%ali {7F (@Q_ ({en7rf[y.png "width=" height= "Bayi" border= "0" hspace= "0" vspace= "0" style= "WIDTH:500PX;HEIGHT:81PX;" alt = "Wkiom1jn-kwyvvyraaaehidbjp8865.png"/>
Str.strip ('/')//clear closure of specified symbols
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/8E/DF/wKiom1jN-FDB6yC0AAAg7tNWwMw454.png "title=" u4d} Dz28_rsvg (uc9]% $X @3.png "width=" height= "0" border= "0" hspace= "0" vspace= "style=" alt= "Wkiom1jn-fdb6yc0aaag7tnwwmw454.png"/>
Str.split ()//String segmentation
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/8E/DE/wKioL1jN_liB5Z94AAALFSopy-c604.png "title=" 2.png "Width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:500px;height:88px; "alt=" Wkiol1jn_ Lib5z94aaalfsopy-c604.png "/>
Str.endswith//Judging the end of a string
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/8E/DE/wKioL1jN_eXBOE6XAAAU7D89uKU139.png "title=" 1.png "Width=" height= "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:500px;height:132px; "alt=" Wkiol1jn_ Exboe6xaaau7d89uku139.png "/>
Str.startswith () //Judge string start
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/8E/DE/wKioL1jOACbzPzXoAAAUKUNNq-k934.png "title=" 7.png "Width=" "height=" 98 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:500px;height:98px; "alt=" Wkiol1joacbzpzxoaaaukunnq-k934.png "/>
Str.lower ()//change string to lowercase
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/8E/E0/wKiom1jN_p-CCDnBAAAMBZokuYo288.png "title=" 3.png "Width=" height= "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:500px;height:83px; "alt=" Wkiom1jn_ P-ccdnbaaambzokuyo288.png "/>
str.upper () //change string to uppercase 650) this.width=650; "Src=" Https://s3.51cto.com/wyfs02/M01/8E /e0/wkiom1jn_wzqrsrgaaak_sg1w_s395.png "title=" 4.png "style=" FLOAT:LEFT;WIDTH:500PX;HEIGHT:86PX; "width=" 500 " height= "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" wkiom1jn_wzqrsrgaaak_sg1w_s395.png "/>
' Specify stitching symbol '. Join (str)//string concatenation
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/8E/DE/wKioL1jN_6XA0at4AAAMhOqf_jg288.png "title=" 6.png "Width=" height= "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:500px;height:68px; "alt=" Wkiol1jn_ 6xa0at4aaamhoqf_jg288.png "/>
String slices:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/8E/E0/wKiom1jN_2ShoZPZAAAM4p0aULA207.png "title=" 5.png "Width=" "height=" 102 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:500px;height:102px; "alt=" Wkiom1jn_ 2shozpzaaam4p0aula207.png "/>
string concatenation:
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/8E/DE/wKioL1jOACfD_JzIAAAMwfSRR8o352.png "style=" width : 500px;height:93px; "title=" 8.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" wkiol1joacfd_ Jziaaamwfsrr8o352.png "/>
There are many built-in methods for strings, but these are common, and I hope you will be helpful to your friends.
This article is from the "Automated Operations" blog, please be sure to keep this source http://hongchen99.blog.51cto.com/12534281/1908091
Python string explanation