>>> num = 123
>>> id(num)
8743872
>>> num = 456
>>> id(num)
13991590095640
>>> num = 123
>>> num1 =888
>>> del num,num1
长整型的取值范围:
python2.7版本中长整型的取值范围为-2**63-1次方至2**63次方
python3中没有long类型,使用int表示长整型
In [1]: 2**63-1
Out[1]: 9223372036854775807L
In [2]: lo1 = 9223372036854775807
In [3]: type(lo1)
Out[3]: int
In [4]: lo2 = 9223372036854775808
In [5]: type(lo2)
Out[5]: long
In [6]: log8 = -2**62
In [7]: type(log8)
Out[8]: int
In [9]: log8 = -2**63-1
In [10]: type(log8)
Out[11]: long
创建复数:
>>> complex1 = 1.2+3.4j
>>> type(complex1)
<class 'complex'>
>>> complex2 = complex(0.3,3.2)
>>> print(complex1,complex2)
(1.2+3.4j) (0.3+3.2j)
>>> nu1 = 89
>>> nu2 = float(nu1) #转换浮点型
>>> type(nu2)
<class 'float'>
>>> nu3 =complex(nu2) #转复数
>>> type(nu3)
<class 'complex'>
>>> print(nu3)
(89+0j)
>>> nu4 = int(nu2) #转整数
>>> type(nu4)
<class 'int'>
>>> nu5 =str(nu4) #转字符
>>> type(nu5)
<class 'str'>
str(x ) 将对象 x 转换为字符串 repr(x ) 将对象 x 转换为表达式字符串 eva l(str ) 用来计算在字符串中的有效Python表达式,并返回一个对象 tuple(s ) 将序列 s 转换为一个元组 list(s ) 将序列 s 转换为一个列表 chr(x ) 将一个整数转换为一个字符 unichr(x ) 将一个整数转换为Unicode字符 ord(x ) 将一个字符转换为它的整数值 hex(x ) 将一个整数转换为一个十六进制字符串 oct(x ) 将一个整数转换为一个八进制字符串
>>> import math #数字处理模块
>>> help(math.ceil) #查看帮助
>>> dir(math) #打印所有方法
['__doc__', '__file__', '__loader__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
>>> nu1 = 12.34
>>> math.ceil(nu1) #取上入整数
13
>>> math.exp(nu1) #返回e的nu1次幂,e为定义的常量
228661.9520568098
>>> math.fabs(nu1) #返回绝对值
12.34
>>> math.floor(nu1) #返回数字的下舍整数部分
12
>>> math.modf(nu1) #返回小数部分与整数部分
(0.33999999999999986, 12.0)
>>> math.sqrt(nu1) #返回平方根
3.5128336140500593
>>> math.e #模块定义的常量e
2.718281828459045
>>> math.pi #模块定义的常量pi
3.141592653589793
内置函数:
>>> abs(11.2) #返回绝对值
11.2
>>> max(12,24) #最大值
24
>>> min(12,24) #最小值
12
>>> pow(2,4) #2**4幂次方
16
>>> round(1.245,3) #返回值的四舍五入值,3为定义到小数第几位
1.245
>>> round(1.245) #默认为0
1
>>> import random #导入模块
>>> random.random() #获取0到1之间的随机数
0.1781419039493949
>>> random.random()
0.914421842727102
>>> ra