Summarize the others ' learning notes for Python:
1. Output redirection to the log file:
F= Open ("LogFileName", "a")
Print >> A, "the output of the content, mainly to have the previous redirection number >>"
F.close () #注意关闭资源
2. Using the From __FUTURE__ Import division, use the new feature to achieve true division,//Still for floor division
3. Boolean operations support and,or,not;& and vertical bars, etc., should be short-circuit operation.
4. List,tuple,map to *n, get new content repeated n times the corresponding type.
5. Decimal number type, you need to import the corresponding module, float is actually not able to be accurately represented.
6. Tuple content can not be changed, referring to the memory address of the tuple content does not change, but its elements point to the location can change, can be regarded as a read-only list.
7. Dictionaries are created in a variety of ways, with the For loop being the key of the Loop dictionary.
8. Enumerate () Get the subscript and value of the sequence respectively
9. List parsing usage and lambda usage are ingenious.
Type (classname,bases,dict) to create a class.
Strname.strip ([chars]) remove certain characters and symbols
12. It is recommended to use tuple mode for multivariate assignment (a,b,c) = (+/-)
Swap operation: x,y=y,x
Sys.getrefcount (object) Gets the number of references to the object, but minus 1
15. The increase in count is: Create, alias reference, parameter pass, container reference
Delete an alias from an existing namespace, reference-1
17. Re-assign a local alias to the commonly used variables introduced from other modules, which can speed up loading.
18. If the user creates an instance that defines nonzero (__nonzero__ ()) or length (__len__ ()) and a value of 0, returns false, the file determines the bool value of the object, the nonzero method is called first, and the length () is not called. method, and returns the length as a bool value.
19. Use the Cpmpile () built-in function to precompile and execute using the EXEC () or eval () method.
20. A slice () can be used to create a slice object, and the NP has a corresponding usage.
21. Comparison, string is starting from the first letter comparison and length independent, lists, tuples and dictionaries are also compared by element order, dictionary is the key comparison
22. Comparison of custom objects is the comparison of IDs
CMP ()/__cmp__ (), str ()/__str__ (), repr ()/__repr__ (), Isinstance ()
24. Type factory function: Int (), long (), float (), complex (), type (), str (), Unicode (), basastring (), Dict (), list (), tuple (), set (), Frozenset (), bool (), Object (), Classmethod (), Staticmethod (), super (), property (), file ()
25. Standard integer type: 0X for 16 binary, 0 for octal, 0b for binary, long integer plus L, size and memory related.
26. Interpreter start parameters Qdivision_style or-qnew or introduce new features using true division
27. * * The power operator has higher precedence than the left Monocular operator.
Coerce (N1,N2) gets a tuple of two numbers that are converted by the type conversion rule.
Divmod (N1,N2) obtains a tuple consisting of quotient and remainder.
Round (Num[,base]) rounded, base specifies the number of decimal places; Floor () gets the largest integer not greater than the original number; and int () almost
Random pseudo-random number generator, Randint (start,end) obtains an integer between uniform (start,end) randomly generated in the range of a floating point, Randrange ([Start,]stop[,step]) Randomly returns a random number of ranges within a range by step, choice (sequence) randomly returns an element in a given sequence.
32. Operators that apply to all sequences, including lists, tuples, and strings: In,not In,+,*,[],slice
List.extend (iterable) appends an iterator to the object. List.insert (index,obj) index exceeds the subscript, increments at the end, if a negative number is exceeded at the beginning plus.
List[iter],tuple ([]), Ste (object) is a string representation that converts an object into an object, basestring cannot be instantiated, and is used as the parent of STR and Unicode.
Reversed (sequence) returns an iterator for reverse access
The. zip returns a list containing tuples
A. Lambda function that can be invoked using a handle plus arguments.
For-else usage, the ELSE clause executes after all elements are cycled, and if break is not executed.
39. Connecting two strings with a join is more efficient.
40. Format operator Auxiliary directives: * Define width or decimal precision,-for left alignment, + + in front of positive numbers, (SP) to display spaces before positive numbers, #显示进制比如% #X, (VAR) mapping variables (dictionary parameters), M.N in M refers to the minimum total width, n is the number of digits after the decimal point
41. Format string accepts dict data: "% (howmany) d days"% {"Howmany": 28}
42.
python-2014.11.19