[Python web development] (3)-one of the basics of Python

Source: Internet
Author: User

Start to calm down and learn the basics of Python: the python tutorial

I read some of the previous chapters today. For more information, see:

 

------------------------------------------- I am a pangpang separator line ------------------------------------------

 

Important points of attention include:

1) Length of Chinese Characters

According to the test, one Chinese Character occupies three. For details, see

 

------------------------------------------- I am a pangpang separator line ------------------------------------------

 

2) in some languages, "=" indicates reference. In python, it is a copy rather than a reference. For details, see:

 

------------------------------------------- I am a pangpang separator line ------------------------------------------

 

3) when calling a function, you can directly specify the parameter name and value without the Parameter order. For details, see:

 

------------------------------------------- I am a pangpang separator line ------------------------------------------

 

4) The Python code specification. After reading this text, I changed the tab to 4-space.

 

Now that you are about to write longer, more complex pieces of Python, it is a good time to talk aboutCoding style. Most versions ages can be written (or more concise,Formatted) In different styles; some are more readable than others. making it easy for others to read your code is always a good idea, and adopting a nice coding style helps tremendously for that.

For python,Pep 8Has emerged as the style guide that most projects adhere to; it promotes a very readable and eye-pleasing coding style. every Python developer shocould read it at some point; here are the most important points extracted for you:

  • Use 4-space indentation, and no tabs.

    4 spaces are a good compromise between small indentation (allows greater nesting depth) and large indentation (easier to read). Tabs introduce confusion, and are best left out.

  • Wrap lines so that they don't exceed 79 characters.

    This helps users with small displays and makes it possible to have several code files side-by-side on larger displays.

  • Use blank lines to separate functions and classes, and larger blocks of code inside functions.

  • When possible, put comments on a line of their own.

  • Use docstrings.

  • Use spaces around operators and after commas, but not directly inside bracketing constructs:A = f (1, 2) + g (3, 4).

  • Name your classes and functions consistently; the convention is to useCamelcaseFor classes andLower_case_with_underscoresFor functions and methods. Always UseSelfAs the name for the first method argument (seeA first look at classesFor more on classes and methods ).

  • Don't use fancy encodings if your code is meant to be used in international environments. plain ASCII works best in any case.

Related Article

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.