Python, final review (1)

What is regular expression

Regular expressions are a powerful tool for string processing, and provide stronger processing capabilities than the methods provided by the string itself.
For example, to determine whether a string is a valid Email address, you can construct a rule (regular expression) to determine whether the string can match.

re module

Python provides support for regular expressions through the re module.

The general step to use re is to first compile the string form of the regular expression into a Pattern instance

Then use the Pattern instance to process the text and get the matching result (a Match instance)

Finally, use the Match instance to obtain information and perform other operations.
The re.match function
re.match tries to match a pattern from the beginning of the string. If the match is not successful at the beginning, match() returns None.
re.match(pattern,string,flags=0)
Insert picture description here
The difference between re.match and re.search
re.match only matches the beginning of the string, if the string does not match the regular expression at the beginning, the match fails, the function returns None
and re .search matches the entire string until a match is found.
Insert picture description here
Insert picture description here

Briefly describe the three characteristics of object-oriented .
Encapsulation, inheritance, and polymorphism
briefly describe how to define class variables and instance variables, and the precautions for using these two variables.
The nature of Python variables: Assigned
1 Ordinary python variables (non-class-related variables) are easy to understand. After being assigned, the variables exist and can be read and written.
2 Python class variables (class variables and instance object variables) are in a certain way It is assigned in a certain place, that is, it can be read and written
2.1 Python class variable is assigned
(1) In the design of the
class, outside the def of the class, it can be assigned through the variable name in the
def through the point of the class object, that is, the class name. The name can be assigned
(2) In the program, the
class name can also be assigned by the point operation of the class object (class name)
2.2 Python instance object variable is assigned
(1) The
variable name can be assigned by the self point operation in the def of the class , Not necessarily in init, but also in other methods that have been called.
(2) In the program,
through the point operation of the instance object, the variable name can be assigned.
Briefly describe the names and functions of the important parameters (at least three) of the open method .
file: Required, file path (relative or absolute path).
mode: optional, file opening mode
buffering: set buffer
encoding: generally use utf8
errors: error level
newline: distinguish newline characters

Guess you like

Origin blog.csdn.net/weixin_43398418/article/details/110679622