python学习之路--numbers
来源:互联网 发布:数据分析平台页面设计 编辑:程序博客网 时间:2024/06/03 20:51
Numberstype
int (10,100)
long (5167466L)
float (12.5)
complex (12.8-3.14j)
a = 10b = 12.5c = 5147638Ld = 5.1 - 3.14jprint 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学习之路--numbers
- LeetCode学习之路-Add Two Numbers
- python学习之路
- Python学习之路
- Python学习之路
- python学习之路
- Python学习之路
- python学习之路
- Python学习之路
- python学习之路
- Python学习之路
- Python学习之路
- python学习之路
- Python学习之路
- leetCode之Add Two Numbers python实现
- Python学习之路---Python Number
- Python学习之路---Python 字符串
- Python学习之路---Python条件语句
- Linux下使用redis
- 支持向量机详解(SVM)
- Oracle12C--对象视图(67)
- 对象可见性规则[java7高级进阶]
- redis相关知识
- python学习之路--numbers
- 633. Sum of Square Numbers (数学)
- Andriodjie——画圆3秒跳转
- App架构经验总结
- 实验5
- django虚拟环境创建
- 类的六个默认成员函数(转)
- Oracle之聚合因子
- 18.jdbc技术