博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python number
阅读量:6423 次
发布时间:2019-06-23

本文共 1984 字,大约阅读时间需要 6 分钟。

1. Basic

var = 1 #int (signed integers)var = 1L #long (long integers )var = 1.1 #floating-pointvar = 3+3j #complex (complex numbers)

  

2. convert

var = 1int(var)long(var)float(var)complex(var) #real part is var, imaginary part is 0complex(x, y) #real part is x, imaginary part is y

  

3. Mathematical function

import mathvar = 1abs(var) #the absolute value of varceil(var)floor(var)cmp(x, y) #If x
y, return 1.exp(var) #e^varfabs(float(var))log(var)log10(var)max(x1, x2, ...)min(x1, x2, ...)modf(var) #This method returns 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) #x^yround(x [,n]) #x rounded to n digits from the decimal point.sqrt(x)

  

4. Random number function

import randomrandom.choice(seq) #returns a random item from a list, tuple, or stringrandom.randrange([start,] stop [,step]) #returns a randomly selected element from range(start, stop, step).#start -- Start point of the range. This would be included in the range.#stop -- Stop point of the range. This would be excluded from the range.#step -- Steps to be added in a number to decide a random number.random.random() #A random float r, such that 0 <= r <=1random.seed([x]) #The method seed() sets the integer starting value used in generating random numbers. Call this function before calling any other random module function.#x -- his is the seed for the next random number. If omitted, then it takes system time to generate next random number.random.shuffle(lst) #Randomizes the items of a list in place. Returns None.random.uniform(x ,y) #A random float r, such that x<=r<=y.

  

5. Trigonometric functions

import mathacos(x)asin(x)atan(x)atan2(y,x) #atan(y/x)cos(x)sin(x)tan(x)hypot(x, y) #Return the Euclidean norm, sqrt(x*x + y*y).degrees(x) #Converts angle x from radians to degrees.radians(x) #Converts angle x from degrees to radians.pie

  

转载于:https://www.cnblogs.com/KennyRom/p/6292397.html

你可能感兴趣的文章
数据中心机房UPS供电系统的全新安全及节能技术设计
查看>>
windows 7 的防火墙设置
查看>>
11.python并发入门(part10 多进程之间实现通信,以及进程之间的数据共享)
查看>>
金蝶KIS专业版“登录时出现问题,请重新输入”终极解决全过程
查看>>
UDP15000端口引起的路由器丢包
查看>>
linux如何使用find命令查找文件
查看>>
LNMP_nginx安装_3
查看>>
apache代理多个tomcat实例
查看>>
Remository3.52简体中文语言包
查看>>
DSL技术分析
查看>>
2015年最新数据库流行排行榜
查看>>
有趣的JavaScript数组
查看>>
3.3. 生成目录深度
查看>>
Linux 动态链接库(.so)的使用
查看>>
春风十里,不如淘宝遇见你——浸润深度学习的淘宝智能搜索
查看>>
WCF开发框架形成之旅---WCF的几种寄宿方式
查看>>
学好数学可以救命
查看>>
java编程之:生成rsa密钥
查看>>
★如何证明自己不是精神病?
查看>>
来自数学君的羊年祝福
查看>>