yanglgzh 发表于 2017-4-28 11:52:22

摘自python的文档

Boolean Operations — and, or, not
Operation    Result
x or y if x is false, then y, else x
x and y if x is false, then x, else y
not x if x is false, then True, else False

Comparisons
Operation   Meaning
< strictly less than
<= less than or equal
> strictly greater than
>= greater than or equal
== equal
!= not equal
is object identity
is not negated object identity

Numeric Types
Operation   Result
x + y sum of x and y   
x - y difference of x and y   
x * y product of x and y   
x / y quotient of x and y   
x // yfloored quotient of x and y
x % y remainder of x / y
-x x negated   
+x x unchanged   
abs(x) absolute value or magnitude of x   
int(x)x converted to integer
float(x) x converted to floating point
complex(re, im) a complex number with real part re, imaginary part im. im defaults to zero.   
c.conjugate() conjugate of the complex number c   
divmod(x, y) the pair (x // y, x % y)
pow(x, y) x to the power y
x ** y x to the power y

Bit-string Operations on Integer Types
Operation    Result
x | y bitwise or of x and y
x ^ y bitwise exclusive or of x and y
x & y bitwise and of x and y
x << nx shifted left by n bits
x >> nx shifted right by n bits
~x the bits of x inverted
Sequence Types — str, bytes, bytearray, list, tuple, range
Operation Result
x in s True if an item of s is equal to x, else False
x not in s False if an item of s is equal to x, else True
s + t the concatenation of s and t
s * n, n * s n shallow copies of s concatenated
s i‘th item of s, origin 0
s slice of s from i to j
s slice of s from i to j with step k
len(s) length of s
min(s) smallest item of s
max(s) largest item of s
Old String Formatting Operations
Conversion Meaning
'd' Signed integer decimal.
'i' Signed integer decimal.
'o' Signed octal value.
'u' Obselete type – it is identical to 'd'.
'x' Signed hexadecimal (lowercase).
'X' Signed hexadecimal (uppercase).
'e' Floating point exponential format (lowercase).
'E' Floating point exponential format (uppercase).
'f' Floating point decimal format.
'F' Floating point decimal format.
'g' Floating point format. Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise.
'G' Floating point format. Uses uppercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise.
'c' Single character (accepts integer or single character string).
'r' String (converts any python object using repr()).
's' String (converts any python object using str()).
'%' No argument is converted, results in a '%' character in the result.
Mutable Sequence Types
Operation Result Notes
s = x item i of s is replaced by x
s = t slice of s from i to j is replaced by the contents of the iterable t
del s same as s = []
s = t the elements of s are replaced by those of t
del s removes the elements of s from the list
s.append(x) same as s =
s.extend(x) same as s = x
s.count(x) return number of i‘s for which s == x
s.index(x[, i[, j]]) return smallest k such that s == x and i <= k < j
s.insert(i, x) same as s =
s.pop() same as x = s; del s; return x
s.remove(x) same as del s
s.reverse() reverses the items of s in place
s.sort(]) sort the items of s in place
页: [1]
查看完整版本: 摘自python的文档