Python (4)

Source: Internet
Author: User

>>>ForNInRange(2,10):...ForXInRange(2,N):...IfN%X==0:...Print(N,' Equals ',xn//< Span class= "n" >x)  ... breakelse: ... # Loop fell through without finding a factor ... print (n ' is a prime number ') Span class= "p" >)  ... 2 is a prime Number3 is a prime number4 equals 2 * 25 is a prime number6 equals 2 * 37 is a prime number8 equals 2 * 49 equals 3 * 3              
 parrot () # required argument Missingparrot (voltage=5.0  ' dead ' ) # non-keyword argument after a keyword argument cannot be assigned with a non-assignable Value. Can be Reversed. parrot (110voltage =220) # Duplicate value for the same argumentparrot (actor= ' John Cleese ' ) # unknown keyword argument 

  • Use 4-space indentation, and no tabs.

    4 Spaces is a good compromise between small indentation (allows greater nesting depth) and large indentation (easier to R Ead). Tabs introduce confusion, and is best left Out.

  • Wrap lines so they don ' t exceed Characters.

    This helps users with small displays and makes it possible to has 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 be CamelCase classes and for lower_case_with_underscores functions and METHODS. Always use as the name of the first method argument (see A First look at Classes for more on self Classes and methods).

  • Don ' t use fancy encodings If your code are meant to being used in international environments. Python ' s default, UTF-8, or even plain ASCII work best in any case.

  • likewise, don ' t use non-ascii characters in identifiers if there are only the slightest chance people speaking a different Language would read or maintain the Code.

Python (4)

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.