>>>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)