String Type ***************
1. Definition of the string:
The first way:
STR1 = ' We are Westos '
The second way:
STR2 = "Our company is Westos"
The Third Way:
STR3 = "" We Are Westos "" "
2. Escape symbols
A backslash plus a single character can represent a special character, usually a non-printable character
\ n: Represents the newline character \ ": represents the double quotation mark itself
\ t: represents the tab character \ ': Represents the single quotation mark itself
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9B/ED/wKiom1lowRfg3tF-AAHNaJgAMro716.png "title=" 234520170714205836.png "style=" Float:none; "alt=" Wkiom1lowrfg3tf-aahnajgamro716.png "/>
3. Sanchong Quotes
Block Comment: Multiple lines of code comment
Doc documentation for functions: Speaking of functions
String formatted output
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9B/EC/wKioL1lowRfjw4WHAAE8IVz9MY8680.png "style=" float : none; "title=" 234520170714205905.png "alt=" Wkiol1lowrfjw4whaae8ivz9my8680.png "/>
4. String Manipulation Preview
The string belongs to the sequence, and the sequence supports the following actions:
Index slices
Judging substring repetition
Connection calculation length
1). Index
Index (S[i]): Gets the element with a specific offset
Gives a string that can output any character, if the index is negative, is equivalent to the number from the back forward.
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9B/EC/wKioL1lowRihY3qcAADsfX3wqxQ761.png "style=" float : none; "title=" 234520170714205926.png "alt=" Wkiol1lowrihy3qcaadsfx3wqxq761.png "/>
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9B/ED/wKiom1lowRfhoZIKAAAqh-DBZbA878.png "style=" float : none; "title=" 234520170714205916.png "alt=" Wkiom1lowrfhozikaaaqh-dbzba878.png "/>
2). Slicing
Slice s[i:j] extracts the corresponding part as a sequence:
The upper boundary is not contained within;
If the slice boundary is not given, the bottom boundary of the slice defaults to 0, and the upper bounds is the length of the string;
Expanded Slice s[i:j:k], where i,j meaning ibid. k is the increment step;
S[:] Gets the element from the offset from 0 to the end, and is a way to implement a valid copy
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/9B/ED/wKiom1lowRjw4yvpAAFA9tQoEYA272.png "style=" float : none; "title=" 234520170714205933.png "alt=" Wkiom1lowrjw4yvpaafa9tqoeya272.png "/>
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9B/EC/wKioL1lownjQuRnHAADfo7nXras664.png "title=" 234520170714210803.png "alt=" Wkiol1lownjqurnhaadfo7nxras664.png "/>
3). Judging substrings
Determine if a sub string is part of the S string:
Sub in S
Sub not in S
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9B/ED/wKiom1lowRnDkTmVAAD9LLKif3Y343.png "style=" float : none; "title=" 234520170714205938.png "alt=" Wkiom1lowrndktmvaad9llkif3y343.png "/>
4). Repeat, connect and calculate length
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9B/EC/wKioL1lowRrSy_D_AAH5gJbvnoA575.png "style=" float : none; "title=" 234520170714205944.png "alt=" Wkiol1lowrrsy_d_aah5gjbvnoa575.png "/>
5. Type conversion of strings
STR (obj) converts other types of content to strings
int (obj) converts a string to an integer
Float (obj) converts a string to a floating-point type
Long (obj) converts a string to a long integer
6. String Common operations:
Str.capitalize ()
-Capitalize the first letter of the string and return the new first letter capitalized string;
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9B/ED/wKiom1lowRrywTMGAAFlrdUhJRs336.png "title=" 234520170714205951.png "style=" Float:none; "alt=" Wkiom1lowrrywtmgaaflrduhjrs336.png "/>
Str.center (Width[,fillchar])
-Returns a new string that is width long, centered on the original character of the new string, filled with the symbol specified by Fillchar, and filled by space when not specified.
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9B/EC/wKioL1lowRviUUVKAAFHGzOnDco861.png "style=" float : none; "title=" 234520170714205958.png "alt=" Wkiol1lowrviuuvkaafhgzondco861.png "/>
Str.count (sub[, start[, end]), int
-Returns the number of times a sub appears in Str, and returns the number of sub occurrences in the specified range if start and end are specified.
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9B/ED/wKiom1lowRySU2X4AAHScSdor78880.png "title=" 234520170714210029.png "style=" Float:none; "alt=" Wkiom1lowrysu2x4aahscsdor78880.png "/>
Str.endswith (suffix[, start[, end]])
-Determines whether the string ends with suffix, if start and end are specified, returns whether the STR substring in the specified range in str ends with suffix, if yes, returns true; otherwise false
Str.startswith (prefix[, start[, end]])
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/9B/EC/wKioL1lowR2yq3nDAADjakiHjug022.png "style=" float : none; "title=" 234520170714210034.png "alt=" Wkiol1lowr2yq3ndaadjakihjug022.png "/>
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9B/ED/wKiom1loxSPwOZfmAAOxeDvdMEA270.png "style=" float : none; "title=" 234520170714211622.png "alt=" Wkiom1loxspwozfmaaoxedvdmea270.png "/>
Str.find (Sub[,start[,end])
-Determine if the sub is in Str, there is a return index value, there is no return-1.
Str.index (Sub[,start[,end])
-The function of the Find method function is the same, if the sub does not exist, throw valueerror exception;
Str.isalnum ()//Determine if all are letters or numbers
Str.isalpha ()//Determine if all are letters
Str.isdigit ()//Determine if all are numbers
Str.islower ()//Determine if all lowercase
Str.isspace ()//Determine if all are English spaces
Str.istitle ()//Judging are not all headings (case-sensitive)
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9B/ED/wKiom1loxSCDAaq_AADR18D24y8540.png "style=" float : none; "title=" 234520170714211504.png "alt=" Wkiom1loxscdaaq_aadr18d24y8540.png "/>
Str.isupper ()//judgment is not all uppercase
Str.join (seq)
-Merges all elements in the sequence seq into a new string, using Str as a delimiter.
Str.replace (Old,new[,count])
-Replaces the old string in str with the new string and returns the replacement string if count specifies that only the first count of the string is replaced
Str.split ([Sep[,maxsplit]])
-Use the SEP string as the delimiter to cut STR, the default is a space;
-Maxsplit represents the cut here
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9B/EC/wKioL1loxSHwhjwUAALoNhGK4V8847.png "title=" 234520170714211556.png "style=" Float:none; "alt=" Wkiol1loxshwhjwuaalonhgk4v8847.png "/>
Str.strip ([chars])
-Returns a string that, when not specified, removes the first and last whitespace from the string that contains the specified chars character in Str.
Str.lower () # #字符串全部转化成小写
Str.upper () # #字符串全部转化成大写
Str.title () # #标准化输出
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9B/EC/wKioL1loxSOTwaAhAAB4KXnfcaI462.png "style=" float : none; "title=" 234520170714211925.png "alt=" Wkiol1loxsotwaahaab4kxnfcai462.png "/>
Example 1:
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9B/ED/wKioL1loyHyRfYG5AAFNCcg5R5c749.png "style=" float : none; "title=" 234520170714213311.png "alt=" Wkiol1loyhyrfyg5aafnccg5r5c749.png "/>
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9B/ED/wKioL1loyJehCTt-AACAVlPlq-Q987.png "title=" 234520170714213241.png "alt=" Wkiol1loyjehctt-aacavlplq-q987.png "/>
Example 2:
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/9B/ED/wKiom1loyS6yWXHyAAE6mRXJ1eM834.png "style=" float : none; "title=" 234520170714213623.png "alt=" Wkiom1loys6ywxhyaae6mrxj1em834.png "/>
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/9B/ED/wKioL1loyS6Ds7M9AADWiZ4oUJw811.png "style=" float : none; "title=" 234520170714213629.png "alt=" Wkiol1loys6ds7m9aadwiz4oujw811.png "/>
python--String Type