I have excerpted some notes on the book:
1. python is an explanatory language.
Inside the computer, the python interpreter converts the source code into an intermediate form called bytecode, and then translates it into the machine language used by the computer and runs it.
2. What is the difference between Version 2.3 and 3.2? For example, check the version number in 3.2? Python-V in 2.3
3. // indicates taking an integer
4. ** symbol Power Operation
5. There is no switch statement, which can be replaced by if... Elif... else... or dictionary.
6. Write true and false statements
7. The while clause can be followed by an else clause.
8. For writing, remember,for..in
Loops are applicable to any sequence. For I in range () is similar to JS writing, and an else clause can be used at last.
9. By default, the step of range is 1. If we provide the third number for range, it will be the step size. For example, range (, 2) provides []. Remember, RangeUpExtend to the second number, that is, itNoContains the second number.
10. Global defines global variables
11. Only those parameters at the end of the parameter table can have default parameter values. That is, you cannot declare a parameter with the default value when declaring a function parameter, and then declare a parameter without the default value.
This is because the value assigned to the form parameter is assigned based on the position. For example, Def func (a, B = 5) is valid, but def func (A = 5, B) isInvalid.
12. Key Parameters
13.
Note:return
The statement is equivalentreturn None
14.pass
The statement indicates an empty statement block in Python.
15. The document string is a multi-line string. Its first line starts with an uppercase letter and ends with a full stop. The second line is empty, and the detailed description starts from the third line.Strongly recommendedYou follow this Convention when using document strings in your functions.
16.
print(printMax.__doc__)
Note that it is double underline or print (Help (printmax ))
17. Remember, the script name is alwayssys.argv
The first parameter in the list. In Java, the first parameter is an external parameter.
18.
Listshoplist = ['apple', 'mango', 'carrot', 'banana']
19.
Tupleszoo = ('wolf', 'elephant', 'penguin')
20.Contain0Or1Project.An empty tuples consist of an empty pair of parentheses, such as myempty = (). However, tuples containing a single element are not that simple. You must be followed by a comma in the first (unique) project so that python can distinguish between a tuple and an object with parentheses in the expression. That is, if you want a tuples containing project 2, you should specify Singleton = (2 ,). Do not add a comma to the list.
21. dictionary, similar to map
22. The sequence slicing operator is followed by a square brackets. The square brackets contain an optional number and are separated by colons. The magic of sequences is that you can access tuples, lists, and strings in the same way.
23. mylist = shoplist # mylist is just another name pointing to the same object!
24. mylist = shoplist [:] # Make a copy by doing a full slice. This is a copy, and 23 is a reference. For more information, see.
25. The file name can be different from the class name, but not Java.
26. Note__del__
Method andDestructorThe concept is similar. Destroyed objects are automatically called after they are created.
27. Method of inheritance: class student (schoolmember): No super keyword.
28. file read/write: F = open ('d:/poem.txt ', 'w ')
29. When using pickle for storage, F = open (shoplistfile, 'wb') is required, and a 'B' is added to indicate binary.
30. Receiving tuples or dictionaries in a function: because there is a * prefix before The args variable, all redundant function parameters will be stored in ARGs as a tuple. If the prefix is **, redundant parameters are considered as Dictionary key/value pairs.
31. Lambda statements are used to create new function objects and return them at runtime.
32.exec
Statement is used to execute Python statements stored in strings or files.
33.eval
The statement is used to calculate the valid Python expression stored in the string.
After reading the book, I wrote the first Python Program (Address Book) with incomplete functions:
User information:
''' <Br/> created on 2011-6-16 <br/> @ Author: Alen <br/> ''' <br/> class person (object ): <br/> ''' <br/> use it to write person 'info <br/> ''' </P> <p> def _ init __ (self, name, email, phone): <br/> self. name = Name <br/> self. email = email <br/> self. phone = phone
Management class:
''' <Br/> created on 2011-6-16 <br/> @ Author: alen <br/> ''' <br/> Import personinfo <br/> info ={}< br/> def addperson (person): <br/> info [person. name] = person </P> <p> If _ name _ = '_ main _': <br/> Print ('------------------- welcome ------------------------------') <br/> Print ('1. add user') <br/> Print ('2. delete user') <br/> Print ('3. revise user') <br/> Print ('4. search user ') <br/> Print (' ---------------------------------------------------- ') <br/> Print ('Please select your choice:') <br/> Number = int (input ()) <br/> If number = 1: <br/> Print ('Please input your name: ') <br/> name = STR (input ()) <br/> Print ('Please input your phone: ') <br/> phone = int (input () <br/> Print ('Please input your email :') <br/> email = STR (input () <br/> P = personinfo. person (name, email, phone) <br/> addperson (p) <br/> Elif number = 2: <br/> pass <br/> Elif number = 3: <br/> pass <br/> Elif number = 4: <br/> Print ('Please input your name: ') <br/> name = STR (input () <br/> If name in info: <br/> Print ('You search is % s: '% info [name]) <br/> Print (Info)
Just run the management class. This is just the end of learning python "~