Python full stack development from getting started to discarding the common modules and regular

Source: Internet
Author: User

What is a module?

Common scenario: A module is a file that contains Python definitions and declarations, and the file name is the suffix of the module name plus the. Py.

In fact, the import loaded module is divided into four general categories:

1 code written using Python (. py file)

2 C or C + + extensions that have been compiled as shared libraries or DLLs

3 packages for a set of modules

4 built-in modules written and linked to the Python interpreter using C

Why use a module?

If you quit the Python interpreter and then re-enter, then the functions or variables you defined previously will be lost, so we usually write the program to a file so that it can be persisted and executed in Python test.py when needed, when test.py is called a scripting script.

With the development of the program, more and more functions, in order to facilitate management, we usually divide the program into a file, so that the structure of the program is clearer and easier to manage. In this case, we can not only use these files as scripts to execute, but also as a module to import into other modules, to achieve the reuse of functionality,

Regular expressions

The first thing you need to know is that when it comes to the regular, it's only related to strings. In the tool I have given you, every word you enter is a string.
Second, if a value in a position does not change, then no rules are required.
For example you want to use "1" to match "1", or "2" to Match "2", directly can match on. This can be done easily with Python's string operations.
Then we'll consider more of the range of characters that can appear in the same position.
character Group: [Character Group] the various characters that may appear in the same position make up a group of characters, and in regular expressions the characters are divided into classes, such as numbers, letters, punctuation, and so on. If you now ask for a position " only one number can appear ", then the character in this position can only be one of the 10 numbers, 0, 1, 2...9.
Regular
Characters to match
The
Results
Description
[0123456789]
8
True
Enumerates all the valid characters in a group of characters, any character in a character group
The same as the "to match" character is considered to match
[0123456789]
A
False
Cannot match because there is no "a" character in the character group
[0-9]
7
True
can also be used-to denote a range, [0-9] and [0123456789] is a meaning
[A-z]
S
True
Similarly, if you want to match all lowercase letters, you can simply use [A-z] to represent
[A-z]
B
True
[A-z] means all uppercase letters
[0-9] [A-f] [A-f]
E
True
Can match a number, case-a~f, to validate hexadecimal characters

Character:

Metacharacters

Metacharacters
Match content
. Match any character other than line break
\w Match letters or numbers or underscores or kanji
\s Match any of the whitespace characters
\d Match numbers
\ n Match a line break
\ t Match a tab
\b Match the end of a word
^ Match the start of a string
$ Match the end of a string
\w
Match non-alphabetic or numeric or underscore or kanji
\d
Match non-whitespace characters
\s
Match non-numeric
A|b
Match character A or character B
()
Matches an expression within parentheses, and also represents a group
[...]
Match characters in a character group
[^...]
Match all characters except characters in a character group

Quantifiers

Quantifiers
Usage Notes
* Repeat 0 or more times
+ Repeat one or more times

Repeat 0 or one time

N Repeat n times
{N,} Repeat N or more times
{N,m} Repeat N to M times

Python full stack development from getting started to discarding the common modules and regular

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.