Concise Python Notes

Source: Internet
Author: User

Tag: Pos split () Assert self func Purpose calculation command--

Numbers: integers, long integers, floating-point numbers, complex numbers

String:
1. Single quotation mark (The Space tab remains the same)
2. Double quotation marks ()
3. Three quotation marks (multi-line string)
4. Escape character (\)
5. Natural string (prefix R)
6.unicode (Prefix u)
7. Non-volatile
Variable identifiers:
1. Start with: uppercase, lowercase, underline
2. Case sensitive
Data type:
1. Objects
2. Logical lines, physical lines (, representing the end of a logical line)
3. Indent (same level indent, called block) Single tab or two or four spaces
Operators and expressions
1. Operator (+,-, *,/,** (Power),//(Fetch integer),% (remainder),<<,>>,& (with), |,^,~,not,and,or,>=,<=,!=,==)
2. Operator Precedence
(1.) Parenthesis Split
(2.) Lambda,or,and,not
3. Expressions
print ' Hello ', 2 * (py + th + on)
Control flow
1. If-elif-else:
2. While-else
3. For-in[range (1,100, step)]
4.break
5.continue
function Def fun ()
1. Formal parameters, arguments
2. Local Variables
3. Default parameters
4. Key parameters (keywords)
5.return
Def someFunction ():
Pass
6.***docstring (document string, function description)
__doc__
Module: A file that contains all of the functions and variables you define
1. Using the SYS module (parameter list) SYS.ARGV receive parameters from the command line
2.PYC file (speed up input module)
3.from-import
4.__name__ (If __name__ = = ' __main__ ':)
5. Write module (module to place the same directory)
6.dir () function dir (__name__) dir (SYS)
Data
Tuple list differences: Tuples immutable, list variable, tuple (), list [];
1. List (variable) class (Type) object (instance) field (you can use these variables/names only when you have an object of that class)
List.append () List.sort () del list[0]
Indexed, sliced, p
2. Tuples (with 0 or 1 item destination tuples)
3. Dictionary {key: value, Key: Value}dict class
Use list in dictionary% (name,value)
Dist.items () returns a list of tuples using each key/value pair in the dictionary
4. Sequence: Index, slice
Index: subscript operation, square brackets
Slices: [sequence name + square brackets: Baotou, not covered tail]
5. Reference
Startwith tests whether a string starts with a given string
In operator whether the given string is part of another string
The Find method is used to find the position of the given string in another string, returning 1 to indicate that the substring cannot be found
STR class JOIN sequence
Writing a Python script
1. Analysis of problems, design procedures (the most serious)
2. Debugging, perfecting the script
3. What (Analysis)
How to (Design)
Write (implement)
Testing (Testing and debugging)
Use (implementation or development)
Maintenance (optimization)
Object-Oriented Programming
1. Concepts: classes, domains (variables belonging to classes), properties
Classes: Class (domain, method)
Self: Class method and Function difference
Class requires an instance
2.__init__ class method
3. Methods for classes and objects (functions and data)
4.** Inheritance and polymorphism
Input/Output
1.file class Read,readline,write,close
2. Storage Pickle Module (pickle,cpickle)
Import--as abbreviation, equivalent to Alias
Dump function (save), load function (FETCH)
Abnormal
1.try: (True) except: (Error)
Try...catch...else
2. Throw an exception (raise statement)
3.try...finally
Python Standard library
SYS (sys.version) (SYS.ARGV) (Sys.stdout,sys.stdin,sys.stderr)
The Os.name string indicates the platform you are using. For example, for Windows, it's ' NT ', and for Linux/unix users, it's ' POSIX '.
The OS.GETCWD () function gets the current working directory, which is the directory path of the current Python script work.
The Os.getenv () and os.putenv () functions are used to read and set environment variables, respectively.
Os.listdir () returns all file and directory names under the specified directory.
The Os.remove () function is used to delete a file.
The Os.system () function is used to run the shell command.
The OS.LINESEP string gives the line terminator used by the current platform. For example, Windows uses ' \ r \ n ', Linux uses ' \ n ' and Mac uses ' \ R '.
The Os.path.split () function returns the directory name and file name of a path.
Special method?
1. Single statement? Do not understand (indent, contained in a statement block)
2. List synthesis (existing list replaced with new list)
3. Receive tuples and lists in functions (*args,** dictionary key-value pairs)
4.LAMBDA: Creates a new function object, which is returned by the runtime
5.exec: Perform eval: calculation
6.assert: Verify Statement repr = ' ' (function: Gets the canonical string of the object)

Concise Python Notes

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.