Python is the most commonly used type, expressed in single quotation marks. A string between three quotes can span multiple lines and can be output as-is.
Character types are not supported in Python, and characters are strings.
CRUD For---strings
[1:3]
[: 6]
---escape character
Most have the same transfer character as other languages
| \v |
Portrait tab |
| \ t |
Horizontal tab |
| \ r |
Enter |
| \f |
Page change |
| \oyy |
Octal number, the character represented by YY, for example: \o12 for newline |
| \xyy |
Hexadecimal number, the character represented by YY, for example: \x0a for line break |
| \other |
Other characters are output in normal format |
Arithmetic of---string
| + |
String connection |
>>>a + b 'hellopython' |
| * |
Repeating output string |
>>>a * 2 'hellohello' |
| [] |
Getting characters in a string by index |
>>>a[1] 'e' |
| [ : ] |
Intercept part of a string |
>>>a[1:4] 'ell' |
| Inch |
Member operator-Returns TRUE if the string contains the given character |
>>>"H" in a True |
| Not in |
Member operator-Returns TRUE if the string does not contain the given character |
>>>"M" not in a True |
| R/r |
Raw string-Raw string: all strings are used directly as literal meanings, without escaping special or non-printable characters. The original string has almost exactly the same syntax as a normal string, except that the first quotation mark of the string is preceded by the letter "R" (which can be case). |
>>>print r \ n ' \n >>> print r'\ n ' \n |
| % |
format string |
Take a look at the next chapter |
---Python's total formatted output
Use of sprintf functions similar to those in the C language
---three quotes
Three quotes allow programmers to escape from the mire of quotes and special strings, keeping a small piece of string in the form of a so-called WYSIWYG (what you see is what you receive) format.
Like what:
hi = "HI"
There ""
Print hi
The content of the output is:
Hi
There
Keep the original style in three quotes, with a default of \ n
--python the built-in function of a string
This piece is quite a lot, you can view the Python manual directly
String.count (str, beg=0, End=len (String)) |
Returns the number of occurrences of STR in a string, if beg or end specifies that the number of STR occurrences in the specified range is returned |
String.endswith (obj, beg=0, End=len (String)) |
Checks whether the string ends with obj, or returns False if beg or end specifies whether to end with obj in the specified range, or True if it is. |
String.find (str, beg=0, End=len (String)) |
Detects if STR is contained in a string, and if beg and end specify a range, the check is contained within the specified range, and returns 1 if the index value is returned. |
String.index (str, beg=0, End=len (String)) |
Just like the Find () method, only if STR does not report an exception in string. |
String.Join (seq) |
Merges all the elements in the SEQ (the string representation) into a new string, using string as a delimiter |
String.partition (str) |
A bit like the combination of find () and split (), from the first position where Str appears, divide the string into a 3-element tuple (STRING_PRE_STR,STR,STRING_POST_STR), if string STR is not included in the STRING_PRE_STR = = string. |
String.Replace (str1, str2, Num=string.count (STR1)) |
Replace the str1 in string with the str2, if NUM is specified, the replacement is no more than num times. |
String.Split (str= "", Num=string.count (str)) |
Slice string with a delimiter of STR, if NUM has a specified value, only the NUM substring is delimited |
String.translate (str, del= "") |
Converts a string of characters according to the table given by STR, which contains 256 characters, The characters to filter out are placed in the Del parameter |
Python's total string