1, the action of annotate: Undertake tagging demonstrative to certain code in the program, enhance order readability
2, the shortcut key Ctrl + / of annotate
3, variable: The open up in be being put inside a space, have a nickname, use the data in visit and storage space
4, variable name is divisional big the ordinary form of a Chinese numeral
5, = is worth variable name
6, variable data type: Whole model (Int) , floating-point (Float) , Boer model (Bool)
Blame is numeric: String (Str) , list (List) , yuan group (Tuple) , dictionary (Dict)
7, with Type (variable) the data type that tests variable
8, whole model: + - */ % is taken beyond
Floating-point: + - */ normally need not he is taken beyond
Boer model: Ture (1) False (0) two number compare return of value is Boer model
9, the computation that is not digital type: Use between string variable + joining together string for example: Name = " Lu Han " Edu = " undergraduate course of record of formal schooling " Info = Name + Edu
10, string variable repeats content of joining together reduplicative with integral use * " hello " *4 repeats string 4 times
11, string and whole model between cannot use + joining together
12, the integer that the format changes the integral %06d with output decimal %d to express to output shows 6, fill insufficiently 0
The digit of fraction of %f floating-point %.3f shows 3
%s string
%% is outputted %
13, the changeover Int of the type (variable) XXX changeover is Int integer
Float (variable) XXX changeover is floating-point model
Str (XX) XX changeover is string
14, variable commutative B, a = A, B
15, accord with of operation of count of operation accord with: + - * / // takes be divided with no remainder % take remainder ** power
Compare operation accord with>> =<<= ! = is equal to==It is Boer that returned result has Ture False only model Bool
And Or Not of logistic operation accord with
Assignment operation ===Judgement
Accord with of compound assignment operation + = -= *= /= //= %=
16, the format of If statement:
If wants the condition of judgement:
The condition holds water implement this code
If the condition is malcontent sufficient, code won't be carried out
Code paragraph retractive bolting for a Tab is 4 blank space
17, output a statement: Input (the content that wants output) the content that the user inputs is string
18, If. . . . Condition of.else process designing is judged (double branch)
Format: If judges a condition:
Contented condition is carried out change code paragraph 1
Else:
Not contented condition implements this code paragraph 2
19, If. . . .elif. . . .else
Format: If judges a condition 1:
If judge a condition 1 contented, executive code paragraph 1
Elif judges a condition 2:
If judge a condition 2 contented, executive code paragraph 2
Elif judges a condition 3:
If judge a condition 3 contented, executive code paragraph 3
Else:
The condition above is not contented carry out this statement
20, If nest
Format: If judges a condition 1:
Contented condition is carried out change code paragraph 1
If judges a condition 2:
Condition 2 contented implement this code
Else:
Not contented condition 1 implement this code
21, can get a random number with Randint
Module of Import Random # guides
Random.randint (0, 10) the random number between # 0-10
22, While circulates
Format: Variable initialization
While condition:
When the condition is contented: Implement this code
When the condition is contented: Implement this code
Update variably
23, While condition 1:
Condition 1 when satisfying, implement this code
While condition 2:
Condition 2 when satisfying, implement this code
24, external While circulates, the While inside circulates for many times
25, the basic format that For circulates: All over all previous
Data of For variable In
Code
26, several output is successive:
Range (Start, stop) computation begins from Start, acquiescent from 0 begin, do not include Stop Range (5) equal in value at Range (0, 5) 0, 1, 2, 3, 4
27, must use together circularly with For
For I In Range (1, 100)
Print (I)
28, End= " "
29, Break and Continue action
What Break exits is all relevant loops
What Continue exits is current circulation, enter circulate the next time
30, element of list List = [1, element 2, element 3. . . ] the index of list (suffix) from 0 those who begin
31, a certain element in getting list
The first element in list of A = List[0]
32, when taking a cost, if exceed the range of index, the program can sign up for a fault
33, the operation with common list:
Increase list.append (data) data is increased in fine, and can add only every time
List.extend ([4, 5, 6, 7, 8, ] ) but iteration list increases many data
List.insert (index, data) showing emplacement inserts data (available element can fill before the position)
Delete Del list [index] delete the data that appoints index
List.remove (data) delete what appear the first times to appoint data
List.pop () the last element in deleting list has return of value, the element that delete
List.pop (index) delete appoint index data
List.clear () clear empty list
Modification list [index] = data) revise the data that appoints index, if data is nonexistent, can sign up for a fault
Inquiry list [index] take a cost according to index, if index is nonexistent, can sign up for a fault
Len (list) the length of list
Whether does list of If data In contain some element in examination list
Sort list.sort () ascend arrange
34, the loop of use For alls over all previous list
Alling over all previous is from A to Z ordinal take out each elements, and execute identical operation
35, the nest of list
The element in a list is a list, so the nest that this is list
36, yuan group of Tuple = (element, element, element. . . )
37, yuan the index of the group from 0 begin
38, yuan group when containing an element only, need adds comma Tuple = at the back of the element (50, )
39, yuan group cannot revise the data inside
40, when examining data type Print (Type (data)
41, yuan the operation of the group
Yuan group.count (data) the frequency that data appears in the element
Len (list) yuan group length
If data In yuan group whether is some element contained in examining yuan of batch
42, the format changes string from the back () essential commerce is one yuan of group
43, the dictionary can store many data, the information related memory
44, definition format of the dictionary
Format: Dict = {key:vAlue, key:vAlue} bolts renown Key is to bolt index bolts value Value is data
45, the dictionary uses key to be worth pair of memory data
46, the use between key name and key value: The value can be any types, key name can be string only, number, yuan group
47, the distinction of dictionary and list:
Dictionary: It is the gather that does not have foreword, visit data through bolting the name comes
List: It is orderly gather, suffix is from 0 those who begin integral
48, tear open a bag
Tuple =(1, 2, 3, 4)
A, b, c, d = Tuple # is OK a data with yuan of medium group undertake tearing open a bag automatically
Print(a)
Print(b)
Print(c)
Print(d)
49, lexical operation, increase delete, revise
Increase a dictionary [key] = data key is nonexistent, can add key value to be opposite; Key exists, can revise key to be worth right value
Delete lexical.pop (key) delete appoint key value to be opposite, return the value that is deleted
Lexical.clear is clear empty dictionary
Modification dictionary [key] = data key is nonexistent, can add key value to be opposite; Key exists, can revise key to be worth right value
Inquiry dictionary [key] be worth according to the extraction of key, bolt the value signs up for a fault to nonexistent meeting
Lexical.keys () can have one by one, get all key names
Lexical.values () can have one by one, get the key value of index
Lexical.items () can have one by one, get all (key, value) key value is right
What acquiesce gets is key name
50, list yuan group string is orderly, index computation is from 0 begin
51, the common operation of string:
Whether is String.isdecimal() judgement string a number
Whether is String.isalpha() judgement string a letter
52, string is searched
String.find (the string that should search) find the suffix bugle call that returns correspondence, did not find those who return is - 1
String.rfind (the string that should search) search from right towards the left
String.index (the string that should search) find the suffix bugle call that returns correspondence, did not find a newspaper fault
String.rindex (the string that should search) from right begin to search
53, of string character replace
String.replace (Old, new, frequency) return a new string, replace the Old in String into New, if Num is appointed, replace do not exceed Num second
54, Str.split (" break up " ) string becomes a list
Str = " on Monday - Tuesday - on Wednesday "
List =str.split(" - " ) # [" on Monday " , " Tuesday " , " on Wednesday " ]
55, string of take out blank
Str.lstrip take out is left (begin) blank character, return a new character
Right of Str.rstrip take out (last) blank character, return a new character
Str.strip take out begins the blank character with fine, return a new character
56, the section of string
Section, can character of the one part in intercept string
The grammar of section:
String [initial index: The index of the end] after before designation interval is belonged to, be being shut, leave [begin index, end index
57, disobey order with what section achieves string
If pace long value is negative number, pour foreword namely for example: Str[: : - 1] this is whole string pour foreword
58, define a function:
Def function name ()
Function body (the code that function encloses)
59, function just can be carried out when function is called
60, the format that the function that contains parameter defines
Def function name (form ginseng 1, form ginseng 2)
The code of function
Form ginseng is understandable be is variable, need not define ahead of schedule, receive solid ginseng to transmit the data that come over
61, function name (solid ginseng, solid ginseng)
The action of form ginseng: Receive the data that solid ginseng transmits, hand the interior of function number as it is said
Solid ginseng: Calling the data that function uses is solid ginseng, direct cost
Form ginseng: Of solid ginseng occupy, terminal, receive solid ginseng to pass the data that come over only
62, the scope of form ginseng:
Use in function interior, in function exterior cannot use this form ginseng
- Without solid ginseng, those who use is acquiescent value, gave solid ginseng, with respect to the value that uses solid ginseng * form joins: Yuan group
** form joins: Dictionary
- Tear open a bag to want to notice: Yuan there is how many value in the group, receive with how many variable
Key word parameter: Appoint corresponding form ginseng to solid ginseng
Key word parameter is to give solid ginseng
Acquiescent parameter is to give form ginseng
To parameter 2 specified key word, did not give parameter 1 specify key word, can sign up for a fault
Set parameter of a key word, set key word parameter to all solid ginseng
- Of function alterable (errant long parameter) use
* expresses yuan of group kind Def Fun (*args)
Variable parameter can receive the solid parameter of aleatoric amount to occupy, and automatic group is wrapped become yuan of group
- The variable parameter of word model
** expresses lexical type Def Fun (**args)
Add a data, the result of output is a dictionary
- Need the return of value of function: Return the result of operation the position that calls to function
In the project, return a result, have other operation, offer return a result to basically want to use for follow-up code, have nothing to do with grammar, if do not have return of value, the value is None
If return of value has many, team package yuan of group, return the call position of function
- Tear open a bag to want to notice: Yuan there is how many value in the group, receive kind of 4 kinds of function with how many variable: Without parameter without return of value without parameter return of value has parameter to without return of value parameter has Range(1 of return of value, several 6) 1-6 is successive, do not include 6 repeat output overall situation of Print("*"*20) of a certain symbol is variable: In function the variable of exterior definition, action limits is whole file
Local and variable: What define in function interior is variable, can use in the interior of function only
If need to revise global variable in the interior of function, need uses Global to have name of statement Global variable
- Faceless function: With the function that the form of expression will come to define, can do a few simple processing only
Lambda form parameter 1, form parameter 2, form parameter 3. . . . : Return of value
Lambda function can receive the parameter of aleatoric amount, and return the value of an expression
F =(lambda Num1, num2:nUm1+num2)(1, 2)
Print(f)
- Guide into module use Import interiorly of a function calls its itself, this function is recursive function of function Step(n) = N * Step(n - 1) Step() implemented form of factorial list derivation: Data of variable In of For of expression of List = [] the type of data list derivation that what deposit in list is the expression that For alls over all previous to come out supports If judgement: If of loop of For of expression of List = [judges a condition] list List, lexical Dict is alterable
Data type Int, bool, float string Str yuan group it is not alterable type
- Visit mode:
R: With read-only means opens a file. The finger of the file will be put in the begin of the file. This is acquiescent mode.
W: Open a file to be used at be being written only. If this file already existed,enclothe its. If this file is nonexistent, found new document.
A: Open a file to be used at increasing. If this file already existed, file finger will be put in the ending of the file. That is to say, new content will be written after already having content. If this file is nonexistent, found new document to undertake be writinged
Rb: Open a file to be used at with binary format read-only. File finger will be put in the begin of the file. This is acquiescent mode
Wb: Open a file to be used at be being written only with binary format. If this file already existed,enclothe its. If this file is nonexistent, found new document
Ab: Open a file to be used at increasing with binary format. If this file already existed, file finger will be put in the ending of the file. That is to say, new content will be written after already having content. If this file is nonexistent, found new document to undertake be writinged.
R+ : Open a file to be used at reading to write. File finger will be put in the begin of the file
W+ : Open a file to be used at reading to write. If this file already existed,enclothe its. If this file is nonexistent, found new document.
A+ : Open a file to be used at reading to write. If this file already existed, file finger will be put in the ending of the file. The meeting when the file is opened is to increase mode. If this file is nonexistent, found new document to be used at reading to write
Rb+ : Open a file to be used at reading to write with binary format. File finger will be put in the begin of the file
Wb+ : Open a file to be used at reading to write with binary format. If this file already existed,enclothe its. If this file is nonexistent, found new document.
Ab+ : Open a file to be used at increasing with binary format. If this file already existed, file finger will be put in the ending of the file. If this file is nonexistent, found new document to be used at reading to write.
- Open a file
Syntactic: Name of file of variable = Open(, visit mode)
Shut a file
Format: Close()
- Read (Num) : Can read access to occupy from inside the file, the port that Num expresses to want to read extraction data from inside the file is spent (the unit is byte) , if did not pass into Num, so express to read all data in taking a file
Reading occupies (Readline) : Read every time take group
Reading occupies (Readlines) : Have the content in whole file according to the means of travel one-time read take, and return is a list, among them each data is an element
- In reading the process that keeps a file, if want to know current position, in can using Tell() to if reading the process that keeps a file,be gotten, need has the word of the operation from another position, can use Seek()
Seek(offset, from) has two parameter
Offset: Deflection quantity, from is from 0 begin ability to use
Seek(2, the begin of 0) file
From: Direction 0: Represent file start
1: Represent current position
2: State the file is last
- What the Rename() that A + writes into content Os module in the position of cursor can complete pair of documents is heavy name
Name again: Rename(needs modification file name, new file name)
Delete a file: Remove()
Found folder: Mkdir(" folder renown " )
Get current operation way: Getcwd()
Get catalog list: Listdir()
Change the way of the operation: Chdir()
Delete a folder: Rmdir() can delete blame empty file only
- Whether does judgement file exist
Ture of existence of Os.path.exist(" file ") is nonexistent False
- Eval(): ? of cane of charm of of location shakes travel У to seek Xue spade to tell Piao of pray of Zhui of Song of a surname of Wo Na food container to attack Jing Mao? kind the pattern plate that establishs a target namely
First kind of ability has a boy or girl friend
Define kind of format: Class kind renown: Name regulation (big hump)
- Establish the pattern of the object:
Cite the variable name of the object = kind renown ()
- Call the method of the object
The variable name of the object. Methodological name ()
101, definition / use attribute
Definition, setting belongs to nature formula: Cite the variable name of the object. Attribute name = data
102, the meaning of Self:
Key word: Basically use in object method, express to call the boy or girl friend of this method
In the method: Can get the boy or girl friend that calls current method, get the attribute of this object and means then
103, object. Attribute = attribute is worth
104, blackart method:
The use of __init__(self) (key)
The initialization method of the object, acquiescent after establishing a target meeting is called, do not need a hand to move call
Define attribute and set initiative value
The use of A, acquiescent parameter
The initialization method of 1) object
The initialization of 2) example
The attribute initialization of 3) object
# normally __init__ calls this method automatically when establishing a target
# __init__ finishs the attribute initialization of the object to work
The B, use that defines parameter oneself
__str__(self)
Print an object with Print directly, can see the address in founding the object that come out to be put inside
This method has sentence of a Return normally, return a value
__del__(self)
It is when the object before destroy by melting or burning, call this method automatically, (analyse compose method)
The action of analyse compose method: Do a few additional works, for instance rubbish reclaims (release variable) , shut file or folder
When Def __init___(self) establishs a target call automatically
Def __str___(self) outputs object of an object Print()
Def__del__(self) object is called automatically by destroy by melting or burning this method
105, enclose
Put attribute and method to to serve as a whole, change an object to handle through example next
Conceal in-house detail, the function that provides an operation to the outside can Print()
Have functional code making a package, put code inside, provide the function of the operation to the outside, conceal in-house detail, you are not in charge of what how come true inside me, you are taken it is OK to use
106, blackart method __init__ , can be acceded by subclass
107, examine kind successive catenary
Format: Kind renown. __mro__
108, multilayer and successive
Grandpa Class kind (Object) : Base kind
Class father kind (grandfather kind) :
Class son kind (father kind) :
109, when father kind with the methodological name of subclass same situation falls, what acquiesce uses is the method in subclass
110, accede more
Subclass (father kind, father kind)
Class Child(Father, mother) :
111, much condition kind much condition basically is to show the method rescripts
112, the use of static method
@staticmethod
Def method name ()
113, two underline were being added before property property demesne is demesne attribute, it is mutual attribute otherwise
114, the method that __new__() belongs to a static state rescripts establish a target, the adduction that must return an object with Return address
115, use Try. . .except. . . Capture unusual
116, common wrong type
NameError names a mistake
IndentationError is retractive and wrong
The type of FileNotFoundError mistake: The file was not found
Io.UnsupportedOperation
Exception convention is wrong base kind
117, Finally is in unusually medium action:
Try:
Try executive code
. . .
Finally
No matter whether happen unusual carry out Finally
Hope you take roundabout way less on the way that learns Python, display here on the attention of Python0 foundation data that I collect, transmit, illicit letter " 01 " can get