The Python character is a basic component of the python program, and the related program is composed of the relevant characters, as well as the actual operation scheme related to the Python string. The following is a detailed introduction of the article, I hope you will get some information after reading the following articles. The following is a detailed description of the article.
Python character digits, letters and symbols, such as $ \@, %, and *) are basic components of python programs. Each program consists of characters. These characters are combined in a meaningful way to indicate a series of commands that the interpreter uses to execute a task. Each character has a corresponding "character code" is sometimes called "integer order value"). For example, an integer of 122 corresponds to the character constant "z".
Python provides the ord function, which takes a character as a parameter and returns the character code of this character. In most modern languages and systems, character values are created based on the Unicode Character Set. Unicode is an international character set that contains many more symbols and letters than the ASCII character set.
- ord("z") >>> 122
- ord("\n") >>>10
Strings in python are a basic data type. Remember, a string is an "immutable sequence" that cannot be changed after being created. This section describes how to use the len function to obtain the year of a string in the teahouse, how to use operators + to connect strings, and how to use the operator % to format a Python string. Python strings also support various methods for other formatting and processing functions.
- capitalize()
The size of the first character. All other uppercase letters are converted to lowercase letters.
- center(width)
Returns the string whose width is width, and fills the original string with spaces on both sides of the center)
- count(substring[.start[,end]])
Returns the number of times that substring appears in the original Python string. If the start parameter is specified, search for [0 starting position] From the start position. If the end parameter is also specified, stop at the end position.
- endswitch(substring[,start[,end]])
If it ends with a string subtring, 1 is returned. If it is not, 0 is returned.
- expandtabs([tabsize])
Returns a new string with all tabs replaced with spaces. The optional tabsize parameter specifies the number of space characters used for a table operator. The default value is 8.
- find(substring[,start[,end]])
Returns the lowest index position of the substring when it appears in the string. If the Python string does not include this substring,-1 is returned. If the start parameter is specified, the search starts from the index location. If the end parameter is also specified, the search is performed in the start: end shard.
- index(substring[,start[,end]])
The same operation as the find method is searched. If no substring is found in the string, A ValueError exception is thrown.
- isalnum()
- .......
- ####
- string1 = "now I am here."
- print string1.center(50)
- print string1.rjust(50)
- print string1.ljust(50)
-
The above Code fills in the length required by the Python string. The center is filled on both sides, the right is filled on the right, and the left is filled on the ljust.