Python notes (9): String operations, python notes
(1)String
Single quotation marks, double quotation marks, and triple quotation marks can all be used as the start and end of a string, and double quotation marks can be used to directly input multiple lines of strings. The triple quotation marks are generally used to write comments for multiple rows.
(2)RAnd \
RConverts a string to the original string, ignoring all escape characters.
\Is an escape character.
(3)String subscript and slice
(4)String in and not in
(5)Change case sensitivity
Method |
Description |
Upper () |
Convert all letters to uppercase (a new string is returned, and the original string will not be changed) |
Lower () |
Convert all letters to lowercase letters (a new string is returned, and the original string will not be changed) |
(6)IsxString Method
Method |
Description |
Isupper () |
Returns TRUE if all characters in the string are uppercase; otherwise, FALSE. |
Islower () |
Returns TRUE if all characters in the string are in lowercase. Otherwise, FALSE is returned. |
Isalpha () |
Returns true if the string contains only letters and is not empty; otherwise, returns false. |
Isalnum () |
Returns true if the string contains only letters and numbers and is not empty; otherwise, returns false. |
Isdecimal () |
Returns true if the string contains only numbers and is not null. Otherwise, returns false. |
Isspace () |
If the string contains only spaces, tabs, and line breaks, and is not empty, true is returned. Otherwise, false is returned. |
Istitle () |
Returns true if the string contains only the words starting with an uppercase character and followed by lowercase letters and is not empty. Otherwise, false is returned. |
(7)Startswith ()And endswith ()
Method |
Description |
Startswith () |
Returns true if it starts with the specified string. Otherwise, returns false. |
Endswith () |
Returns true if it ends with a specified string. Otherwise, false is returned. |
(8)Join ()And split ()
Method |
Description |
Join () |
Concatenates strings in the list to form a separate string |
Split () |
Returns a list of strings separated by spaces by default. You can also specify parameters. For example, in ps. split (':', 1), the first parameter is separated by:, and the second parameter is the maximum number of splits. By default, the parameter is split as much as possible. |
(9)Strip (), Lstrip (), rstrip ()
Method |
Description |
Strip () |
Removes spaces, tabs, and line breaks from the left and right sides) |
Lstrip () |
Delete blank characters (spaces, tabs, and line breaks) on the left) |
Rstrip () |
Delete blank characters (spaces, tabs, and line breaks) on the Right) |
(10)PyperclipModule
Pip install pyperclip
1 import pyperclip2 3 # copy data to clipboard 4 pyperclip. copy ('Hello word') 5 # paste clipboard content 6 print (pyperclip. paste ())