python學習之路--numbers


Numberstype

int   (10,100)

long (5167466L)

float (12.5)

complex (12.8-3.14j)

a = 10
b = 12.5
c = 5147638L
d = 5.1 - 3.14j
print type(a)
print type(b)
print type(c)
print type(d)

結果:

<type 'int'>
<
type 'float'>
<
type 'long'>
<
type 'complex'>

 Number TypeConversion

·        int(x) to convert x to aplain integer.

·        long(x) to convert x toa long integer.

·        float(x) to convert x toa floating-point number.

·        complex(x)/ complex(x, y) toconvert x to a complex number with real part x and imaginary part zero.

Mathematical Functions

Function

Returns ( description )

abs(x)

The absolute value of x: the (positive) distance between x and zero.

ceil(x)

The ceiling of x: the smallest integer not less than x

cmp(x, y)

-1 if x < y, 0 if x == y, or 1 if x > y

exp(x)

The exponential of x: ex

fabs(x)

The absolute value of x.

floor(x)

The floor of x: the largest integer not greater than x

log(x)

The natural logarithm of x, for x> 0

log10(x)

The base-10 logarithm of x for x> 0 .

max(x1, x2,...)

The largest of its arguments: the value closest to positive infinity

min(x1, x2,...)

The smallest of its arguments: the value closest to negative infinity

modf(x)

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.

pow(x, y)

The value of x**y.

round(x [,n])

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.

sqrt(x)

The square root of x for x > 0

Random Number Functions

隨機數字用於游戲,模擬,測試,安全和隱私應用。 Python包含以下常用功能。

Function

Description

choice(seq)

A random item from a list, tuple, or string.

randrange ([start,] stop [,step])

A randomly selected element from range(start, stop, step)

random()

A random float r, such that 0 is less than or equal to r and r is less than 1

seed([x])

Sets the integer starting value used in generating random numbers. Call this function before calling any other random module function. Returns None.

shuffle(lst)

Randomizes the items of a list in place. Returns None.

uniform(x, y)

A random float r, such that x is less than or equal to r and r is less than y

 



注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



python學習之路-繼承 Python 學習之路(三) Python學習之路2 學習PYTHON之路, DAY 3 python學習之路重點 python學習之路(1) Python學習之路之一 python學習之路二 python學習之路7(列表) 我的python學習之路-02
 
粤ICP备14056181号  © 2014-2021 ITdaan.com