Вы находитесь на странице: 1из 5

1

Windows path setup: Math Function abs(x) ceil(x) cmp(x, y) exp(x) fabs(x) floor(x) log(x) log10(x) max(x1, x2,...) min(x1, x2,...) modf(x) pow(x, y) round(x [,n]) sqrt(x) path %path%;C:\Python

Returns ( description ) The absolute value of x: the (positive) distance between x and zero. The ceiling of x: the smallest integer not less than x -1 if x < y, 0 if x == y, or 1 if x > y The exponential of x: ex The absolute value of x. The floor of x: the largest integer not greater than x The natural logarithm of x, for x> 0 The base-10 logarithm of x for x> 0 The largest of its arguments: the value closest to positive infinity The smallest of its arguments: the value closest to negative infinity The fractional and integer parts of x in a two-item tuple. Both parts have the same sign as x. The integer part is returned as a float. The value of x**y. x rounded to n digits from the decimal point. Python rounds away from zero as a tie-breaker: round(0.5) is 1.0 and round(-0.5) is -1.0. The square root of x for x > 0

acos(x) asin(x) atan(x) atan2(y, x) cos(x) hypot(x, y) sin(x) tan(x) degrees(x) radians(x)

Returns the arc cosine of x, in radians. Returns the arc sine of x, in radians. Returns the arc tangent of x, in radians. Returns atan(y / x), in radians. Returns the cosine of x radians. Returns the Euclidean norm, sqrt(x*x + y*y). Returns the sine of x radians. Returns the tangent of x radians. Converts angle x from radians to degrees. Converts angle x from degrees to radians.

Pi E Random Function choice(seq) randrange ([start,] stop [,step]) random() seed([x])

The mathematical constant pi. The mathematical constant e.

shuffle(lst) uniform(x, y) SN 1 2 3 4 5 6 7

Description A random item from a list, tuple or string. A randomly selected element from range(start, stop, step) A random float r, such that 0 is less than or equal to r and r is less than 1 Sets the integer starting value used in generating random numbers. Call this function before calling any other random module function. Returns None. Randomizes the items of a list in place. Returns None. A random float r, such that x is less than or equal to r and r is less than y

Methods with Description capitalize() Capitalizes first letter of string center(width, fillchar) Returns a space-padded string with the original string centered to a total of width columns count(str, beg= 0,end=len(string)) Counts how many times str occurs in string or in a substring of string if starting index beg and ending index end are given decode(encoding='UTF-8',errors='strict') Decodes the string using the codec registered for encoding. encoding defaults to the default string encoding. encode(encoding='UTF-8',errors='strict') Returns encoded string version of string; on error, default is to raise a ValueError unless errors is given with 'ignore' or 'replace'. endswith(suffix, beg=0, end=len(string)) Determines if string or a substring of string (if starting index beg and ending index end are given) ends with suffix; returns true if so and false otherwise expandtabs(tabsize=8) Expands tabs in string to multiple spaces; defaults to 8 spaces per tab if tabsize not provided

2
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 find(str, beg=0 end=len(string)) Determine if str occurs in string or in a substring of string if starting index beg and ending index end are given; returns index if found and -1 otherwise index(str, beg=0, end=len(string)) Same as find(), but raises an exception if str not found isalnum() Returns true if string has at least 1 character and all characters are alphanumeric and false otherwise isalpha() Returns true if string has at least 1 character and all characters are alphabetic and false otherwise isdigit() Returns true if string contains only digits and false otherwise islower() Returns true if string has at least 1 cased character and all cased characters are in lowercase and false otherwise isnumeric() Returns true if a unicode string contains only numeric characters and false otherwise isspace() Returns true if string contains only whitespace characters and false otherwise istitle() Returns true if string is properly "titlecased" and false otherwise isupper() Returns true if string has at least one cased character and all cased characters are in uppercase and false otherwise join(seq) Merges (concatenates) the string representations of elements in sequence seq into a string, with separator string len(string) Returns the length of the string ljust(width[, fillchar]) Returns a space-padded string with the original string left-justified to a total of width columns lower() Converts all uppercase letters in string to lowercase lstrip() Removes all leading whitespace in string maketrans() Returns a translation table to be used in translate function. max(str) Returns the max alphabetical character from the string str min(str) Returns the min alphabetical character from the string str replace(old, new [, max]) Replaces all occurrences of old in string with new or at most max occurrences if max given rfind(str, beg=0,end=len(string)) Same as find(), but search backwards in string rindex( str, beg=0, end=len(string)) Same as index(), but search backwards in string rjust(width,[, fillchar]) Returns a space-padded string with the original string right-justified to a total of width columns. rstrip() Removes all trailing whitespace of string split(str="", num=string.count(str)) Splits string according to delimiter str (space if not provided) and returns list of substrings; split into at most num substrings if given splitlines( num=string.count('\n')) Splits string at all (or num) NEWLINEs and returns a list of each line with NEWLINEs removed startswith(str, beg=0,end=len(string)) Determines if string or a substring of string (if starting index beg and ending index end are given) starts with substring str; returns true if so and false otherwise strip([chars]) Performs both lstrip() and rstrip() on string swapcase() Inverts case for all letters in string title() Returns "titlecased" version of string, that is, all words begin with uppercase and the rest are lowercase translate(table, deletechars="") Translates string according to translation table str(256 chars), removing those in the del string upper() Converts lowercase letters in string to uppercase zfill (width) Returns original string leftpadded with zeros to a total of width characters; intended for numbers, zfill() retains any sign given (less one zero) isdecimal() Returns true if a unicode string contains only decimal characters and false otherwise

Lists Python Expression len([1, 2, 3]) [1, 2, 3] + [4, 5, 6] ['Hi!'] * 4 3 in [1, 2, 3] for x in [1, 2, 3]: print x,

Results 3 [1, 2, 3, 4, 5, 6] ['Hi!', 'Hi!', 'Hi!', 'Hi!'] True 1 2 3

Description Length Concatenation Repetition Membership Iteration

L = ['spam', 'Spam', 'SPAM!'] Python Expression L[2] L[-2] L[1:]

Results 'SPAM!' 'Spam' ['Spam', 'SPAM!']

Description Offsets start at zero Negative: count from the right Slicing fetches sections

3
SN 1 2 3 4 5 SN 1 2 3 4 5 6 7 8 9 Function with Description cmp(list1, list2) Compares elements of both lists. len(list) Gives the total length of the list. max(list) Returns item from the list with max value. min(list) Returns item from the list with min value. list(seq) Converts a tuple into list. Methods with Description list.append(obj) Appends object obj to list list.count(obj) Returns count of how many times obj occurs in list list.extend(seq) Appends the contents of seq to list list.index(obj) Returns the lowest index in list that obj appears list.insert(index, obj) Inserts object obj into list at offset index list.pop(obj=list[-1]) Removes and returns last object or obj from list list.remove(obj) Removes object obj from list list.reverse() Reverses objects of list in place list.sort([func]) Sorts objects of list, use compare func if given Results 3 (1, 2, 3, 4, 5, 6) ('Hi!', 'Hi!', 'Hi!', 'Hi!') True 1 2 3 Description Length Concatenation Repetition Membership Iteration

Tuples Python Expression len((1, 2, 3)) (1, 2, 3) + (4, 5, 6) ['Hi!'] * 4 3 in (1, 2, 3) for x in (1, 2, 3): print x, Dictionaries SN 1 2 3 4 5 6 7 8 9 10 str.partition(sep)

Methods with Description dict.clear() Removes all elements of dictionary dict dict.copy() Returns a shallow copy of dictionary dict dict.fromkeys() Create a new dictionary with keys from seq and values set to value. dict.get(key, default=None) For key key, returns value or default if key not in dictionary dict.has_key(key) Returns true if key in dictionary dict, false otherwise dict.items() Returns a list of dict's (key, value) tuple pairs dict.keys() Returns list of dictionary dict's keys dict.setdefault(key, default=None) Similar to get(), but will set dict[key]=default if key is not already in dict dict.update(dict2) Adds dictionary dict2's key-values pairs to dict dict.values() Returns list of dictionary dict's values

Split the string at the first occurrence of sep, and return a 3-tuple containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return a 3tuple containing the string itself, followed by two empty strings.

String format The grammar for a replacement field is as follows: replacement_field field_name arg_name attribute_name element_index index_string conversion format_spec format_spec fill align sign width precision type "s" | "x" | ::= ::= ::= ::= ::= ::= ::= ::= "{" [field_name] ["!" conversion] [":" format_spec] "}" arg_name ("." attribute_name | "[" element_index "]")* [identifier | integer] identifier integer | index_string <any source character except "]"> + "r" | "s" <described in the next section>

::= [[fill]align][sign][#][0][width][,][.precision][type] ::= <any character> ::= "<" | ">" | "=" | "^" ::= "+" | "-" | " " ::= integer ::= integer ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "X" | "%"

The meaning of the various alignment options is as follows: Option '<' '>' '=' '^' Meaning Forces the field to be left-aligned within the available space (this is the default for most objects). Forces the field to be right-aligned within the available space (this is the default for numbers). Forces the padding to be placed after the sign (if any) but before the digits. This is used for printing fields in the form +000000120. This alignment option is only valid for numeric types. Forces the field to be centered within the available space.

The sign option is only valid for number types, and can be one of the following: Option '+' '-' space Meaning indicates that a sign should be used for both positive as well as negative numbers. indicates that a sign should be used only for negative numbers (this is the default behavior). indicates that a leading space should be used on positive numbers, and a minus sign on negative numbers.

The ',' option signals the use of a comma for a thousands separator. For a locale aware separator, use the 'n' integer presentation type instead. The precision is a decimal number indicating how many digits should be displayed after the decimal point for a floating point value formatted with 'f' and'F', or before and after the decimal point for a floating point value formatted with 'g' or 'G'. For non-number types the field indicates the maximum field size - in other words, how many characters will be used from the field content. The precision is not allowed for integer values. Type 'b' 'c' 'd' 'o' 'x' 'X' 'n' None Meaning Binary format. Outputs the number in base 2. Character. Converts the integer to the corresponding unicode character before printing. Decimal Integer. Outputs the number in base 10. Octal format. Outputs the number in base 8. Hex format. Outputs the number in base 16, using lower- case letters for the digits above 9. Hex format. Outputs the number in base 16, using upper- case letters for the digits above 9. Number. This is the same as 'd', except that it uses the current locale setting to insert the appropriate number separator characters. The same as 'd'.

5
'e' 'E' 'f' 'F' 'g' Exponent notation. Prints the number in scientific notation using the letter e to indicate the exponent. The default precision is6. Exponent notation. Same as 'e' except it uses an upper case E as the separator character. Fixed point. Displays the number as a fixed-point number. The default precision is 6. Fixed point. Same as 'f'. General format. For a given precision p >= 1, this rounds the number to p significant digits and then formats the result in either fixed-point format or in scientific notation, depending on its magnitude. The precise rules are as follows: suppose that the result formatted with presentation type 'e' and precision p-1 would have exponent exp. Then if -4 <= exp < p, the number is formatted with presentation type 'f' and precision p-1-exp. Otherwise, the number is formatted with presentation type 'e' and precision p-1. In both cases insignificant trailing zeros are removed from the significand, and the decimal point is also removed if there are no remaining digits following it. Positive and negative infinity, positive and negative zero, and nans, are formatted as inf, -inf, 0, 0 and nan respectively, regardless of the precision. A precision of 0 is treated as equivalent to a precision of 1. The default precision is 6. General format. Same as 'g' except switches to 'E' if the number gets too large. The representations of infinity and NaN are uppercased, too. Number. This is the same as 'g', except that it uses the current locale setting to insert the appropriate number separator characters. Percentage. Multiplies the number by 100 and displays in fixed ('f') format, followed by a percent sign. The same as 'g'.

'G' 'n' '%' None

>>> "{0}, {0:X>+20.4f}".format(pi*1e6) '3141592.653589793, XXXXXXX+3141592.6536' >>> "{0:\^+20.4f} and {1}".format(pi*1000, pi) '\\\\\\\\\\+3141.5927\\\\\\\\\\ and 3.141592653589793' >>> "{0}, {0: >20,.0f}".format(pi*1e6) '3141592.653589793, 3,141,593' >>> "int: {0:d}; hex: {0:x}; 'int: 42; hex: 2a; oct: 52; oct: {0:o}; bin: {0:b}".format(42) bin: 101010'

Вам также может понравиться