. Net programmer Python path --- Python basics, python --- python
Recently, I am curious about dynamic languages. So I chose the Python language.
I. Python basics:
1. print outputs data to P
The path to python practice (2-Basic python syntax, traffic control), python-python
For Tom, it is really hard to read the code, the progress is very slow, and the mind is quite complicated, walking silently, hoping to turn persistence into a habit and learn the Code with hard work.
I. character encoding/variable
1. ch
).
(2) match any single character (.)Point character or period (.) the symbol matches any single character except NEWLINE (the Python regular expression has a compilation identifier [S or DOTALL], which can remove this restriction so that (.) include line breaks when matching. Whether it is letters, numbers, blank characters that do not contain "\ n", printable characters, non-printable characters, or symbols, they can be matched. Match a dot (.) it
Python, quantifiers are greedy by default (in a few languages, they may also be non-Greedy by default), and always try to match as many characters as possible; in non-greedy, the opposite is true, always try to match as few characters as possible. For example, if the regular expression "AB *" is used to find "abbbc", "abbb" is found ". If we use a non-Greedy quantizer "AB *?", "A" is found ".
Note: We generally use the non-Greedy mode for extraction.
; 1 + 2 + \4 + 512>>> Print \'Hello. world'Hello. world
2. original string
The original string starts with r. You can add any character to the original string. The output string contains the backslash used for escape. However, you cannot enter a backslash at the end of the string:
Copy codeThe Code is as follows:>>> Print \'Hello. world'Hello. world>>> Print r'let \'s go! 'Let \'s go!>>> Print r'this is ill
may be slightly different, but it is also easy to understand. You can see the examples and use them several times.
Lists the Python-supported regular expression metacharacters and syntaxes:
1.2. Greedy and non-Greedy modes of quantifiers
Regular Expressions are usually used to search for matched strings in the text. In Python, quantifiers are greedy by default (in a few languages, they may also be non-Gre
that you use codecs. open to replace open. If the LogPath file is saved in UTF-8 encoding format:LogLine = open (LogPath) ==> LogLine = codecs. open (LogPath, 'R', 'utf-8 ')Character encoding in python
What you are talking about is to put the string:\ U3232 \ u6674Itself, can it be converted to unicode characters?You can use:SlashUStr = "\ u3232 \ u6674 ";DecodedUniChars = slashUStr. decode ("unicode-escape ");Print "decodedUniChars =", decodedUniCha
, the path of the backslash, this is the result we want. Of course this path is the Python installation path on my computer, each person's installation path may be different, just need to find the Python installation path, and then copy it.5, after copying the Python path, go back to the desktop, find "My Computer", ri
examples of fancy and a few more times you can understand them.Lists the regular expression meta characters and syntax supported by Python:1.2. Greedy mode and non-greedy mode of counting quantifiersRegular expressions are typically used to find matching strings in text. The number of words in Python is greedy by default (which may be the default non-greedy in a few languages), always trying to match as ma
span rows, you can use three quotation marks, and the quotation marks do not need to use escape characters.
>>> str='''hello worldhello 'cathy'hello chenjing'''>>> print strhello worldhello 'cathy'hello chenjing
Original string
The original string starts with r. The original string does not treat the backslash as a special character. Each character entered in the original string is directly output in the same way, but the original string cannot end w
slightly different, but it is also easy to understand. You can see the examples and use them several times.
Lists the Python-supported regular expression metacharacters and syntaxes:1.2. Greedy and non-Greedy modes of quantifiers
Regular Expressions are usually used to search for matched strings in the text. In Python, quantifiers are greedy by default (in a few languages, they may also be non-Greedy by de
Python basic data type, python Data Type
Variables in Python do not need to be declared. Each variable must be assigned a value before it can be used.
In Python, a variable is a variable and a memory address pointer. It has no type. What we call "type" is the type of the object in memory referred to by the variable. Si
Python-python interpreter execution, python-python
Recently, due to the need of the company, I have been familiar with the magic language of python, which gives me the feeling that development is fast and the code is concise.
Let's start by listing the differences between th
via: | d = {} | for k, v in iterable: | d[k] = v | dict(**kwargs) -> new dictionary initialized with the name=value pairs | in the keyword argument list. For example: dict(one=1, two=2) | | Methods defined here: | | __cmp__(...) | x.__cmp__(y)
10. PEP-8 compatible string connection
PEP8 is the Python coding style guide. Aside from others, PEP8 requires that each line contain no more than 80 characters, and the excess part should be wrapped and inden
Regular Expressions in python (re module) and python Regular Expressions
I. Introduction
Regular Expressions are a small and highly specialized programming language. In python, programmers can directly call the re module to implement regular expression matching. The regular expression mode is compiled into a series of bytecode and then executed by the matching en
, [ABC] will match any one of the characters in "a", "B", or "C", or you can use the interval [a-c] to represent the same character set, and the former effect is the same. If you only want to match lowercase letters, then RE should be written as [A-z].Metacharacters does not work in the category. For example, [akm$] will match the character "a", "K", "M", or "\ (any of the" \)"is usually used as a meta-character, but in the character category, its attributes are removed and reverted to normal ch
Python learning notes (7) Python string (1), learning notes python
String
A String is a String of digits, letters, and underscores. It is enclosed by double quotation marks or single quotation marks.
1 >>> "hello world"2 'hello world'3 >>> 'hello world'4 'hello world'5 >>> "250"6 '250'7 >>> type("200")8
The following example:
The first line of a syntax error con
*? "," A "is found ".
1.3. slashes
Like most programming languages, regular expressions use "\" as escape characters, which may cause backlash troubles. If you need to match the character "\" in the text, four Backslash "\" will be required in the regular expression expressed in programming language "\\\\": the first two and the last two are used to convert them into backslashes in the programming language, convert them into two backslashes, and then
}...'>>> re.sub(pat, 'Mr. Gumby',text)'Dear Mr. Gumby...'
Re. escape function, which can be used to escape all characters in the string that may be interpreted as regular operators.
If the string is long and contains many special characters and you do not want to input a large number of backslash characters, you can use this function:
>>> re.escape('www.python.org')'www\\.python\\.org'>>> re.escape('but wh
execution:1.4 Python object to stringMany Python objects can be converted to strings using the STR function:The result of the above instance execution:1.5 string as Sequence type processingBecause a string is actually a sequence of characters, it can be treated as a sequence type (such as a list, a tuple, and so on):The result of the above instance execution:1.6 Python
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.