Python basics (GIL lock, re module, regular expressions)

GIL lock

GIL lock:
Global Interpretation Lock (GIL), the underlying lock of python. The threads in python are essentially pseudo-multithreaded. The GIL is used in cpython to control the execution of threads, which cannot give play to the advantages of multi-core processors, compared to true The thread efficiency is low.
This lock is used to ensure that only one thread can execute at the same time

re module

The re module is a module for processing regular expressions provided by python. It provides various regular expression processing functions. These functions can be simply divided into two categories: character query matching functions and string splitting and replacing functions.
String query matching function

re.match(规则,字符串)
	从头开始按照规则去指定的字符中匹配,只匹配字符串的开头,如果不符合规则则返回None
re.search(规则,字符串)
	去到整个字符串中按照规则去匹配,返回第一个匹配到的字符串,查不到返回None
re.findall(规则,字符串)
	到整个字符串中按照规则匹配所有符合要求的字符,如果没有返回一个空列表
re.finditer(规则,字符串)
	和findall功能相同,只不过返回的是一个可迭代对象
re.fullmatch(规则,字符串)
	根据规则,向指定的字符串整体匹配,检测字符串的整体格式是否符合规则,不符合返回None,符合返回match对象

String split replacement function

re.sub(被替换的值,想替换的值,字符串)
	替换方法,根据规则去替换字符
re.split(以什么为切割符,字符串)
	以什么为切割符对字符串进行切割,返回的是一个列表

Parameter introduction:

	re.I 匹配时忽略大小写
	re.M  多行匹配
	re.S 让‘ . ’可以匹配所有的单个字符包括换行符
		' . ' 元字符 匹配单个的除换行符以外的任意字符

Regular expression

Regular expression: Also called regular expression, regular expression is an independent technology, not a
regular expression metacharacter unique to a certain programming language
Insert picture description here
**Regular expression quantifier
Insert picture description here
Regular expression range matches
in regular expression , For character matching, in addition to the shortcut metacharacter matching, there is another range matching method using square brackets
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44781625/article/details/108652010