Python's re modules are commonly used in 5 ways, namely Re.match Re.search re.findall re.split re.sub.Before you introduce the five methods, you need to introduce the basis of the regular.. Represents any character, except \ nthe \ escape
1. Get Python idle current working directory:1 Import OS 2 os.getcwd ()2. Change the current working directory ("R" is required in front of the directory, otherwise it will report a syntax error):Os.chdir (R" working directory ")3. Run a function
1. What is the difference between a list, a tuple, a dictionary?The ① list is the brackets [], the tuples are parentheses (), the dictionary is curly braces {}② lists are ordered, tuples are ordered, dictionaries are unorderedThe ③ list stores
One, the Eval functionThe function of the Python eval () function: evaluates the string str as a valid expression and returns the result of the calculation.Syntax: eval (source[, globals[, locals]), valueParameters:Source: The code object returned
1 opening and closing of filesOpen itIn Python, using the Open function, you can open a file that already exists, or create a new fileOpen (file name, access mode)Examples are as follows: f = open(‘test.txt‘, ‘w‘)Description
access
Python various types of conversionsStudied: 79204008547818int (x [, Base]) converts x to an integer long (x [, Base]) converts X to a long integer, float (x) converts x to a floating-point number complex (real [,
ImportLinecacheImportSmtplibImport TimeImportLinecacheImportRandom#calculate the number of TXT lines, 163 account _2.txt, each row is stored an account password! txt= Open (R'F:\163 Account _2.txt','R') Data=Txt.read () txt.close () n= Data.count ('\
#字符串#老式的字符串格式化%, in order such as:# s= "I am%s, age%d"% (' Alex ', 18)# print (s)#加号表示右对齐, the minus sign is left-aligned, and if it is 0, it must be a number-%04d# s= "I am% (N1) +10s,age% (n2) +10d"%{"N1": ' Alex ', ' N2 ': 18}# print
########################################################################## Dict# Dict# dic = {# "K1": ' V1 ',# "K2": ' V2 '# }# 1 Create a dictionary based on the sequence, and specify a uniform value# v = Dict.fromkeys (["K1", 123, "999"],123)#
To print the 9*9 multiplication table:Print ' \ n '. Join ([') '. Join (['%s*%s=%-2s' for in for in range (1,10)]) 1*1=11*2=2 2*2=41*3=3 2*3=6 3*3=91*4=4 2*4=8 4=12 4*4=161*5=5 2*5=10 3*5=15 4*5=20 5*5=251*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6
One: The order of the in-stack in the statementSame as other languages (c,c++, etc.) into the stack order is the right end of the first execution into the stack (python3.5), before the python2.7 in the stack order is left
Regular expressions
Basic syntax meta-character
Code
Description
Example
.
Match any character except for a line break
[ABC]
The character set can only represent one
Dict--DictionaryA set of key sets that contains the corresponding key to value.Python's built-in dictionary, which becomes a map in other languages, uses key-value storage with a few blocks of lookup speed. Compared with list, Dict features:The dict
Networkx is a third-party package in Python that makes it easy to invoke the calculations of various graph algorithms. The visualization of graphs can be realized by calling Python drawing package matplotlib.1. InstallationJust sort it out. How to
This article through an example to explain in detail the Python class, inheritance and polymorphism of the definition and usage, very practical, the need for small partners can refer to the following
Definition of Class
If you want to define a
This article mainly introduces the implementation of Python to confirm whether the string contains the instance of the specified string, has a certain reference value, now share to everyone, the need for friends can refer to
Sometimes we need to
This article mainly introduces the use of TensorFlow to achieve lasso regression and ridge regression algorithm example, has a certain reference value, now share to everyone, the need for friends can refer to
There are also some regularization
This article mainly introduces the Python to solve JS file Utf-8 encoding garbled problem, very good, with reference value, the need for friends can refer to the next
HTML file introduced JS file, display garbled!
JS file for Utf-8 encoding (no BOM)
Below for you to share a Python find characters in the string position instances, has a good reference value, I hope to be helpful to everyone. Come and see it together.
str_1= ' wo shi yi zhi da da niu ' char_1= ' i ' Npos=str_1.index (char_1)
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