码迷,mamicode.com
首页 > 编程语言 > 详细

Python number

时间:2017-01-17 12:35:10      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:max   gre   dia   dig   rand   ...   exp   dea   idea   

1. Basic

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

  

2. convert

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

  

3. Mathematical function

import math

var = 1
abs(var) #the absolute value of var
ceil(var)
floor(var)
cmp(x, y) #If x<y, return -1. If x==y, return 0. If x>y, return 1.
exp(var) #e^var
fabs(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^y
round(x [,n]) #x rounded to n digits from the decimal point.
sqrt(x)

  

4. Random number function

import random

random.choice(seq) #returns a random item from a list, tuple, or string

random.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 <=1

random.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 math

acos(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.



pi
e

  

Python number

标签:max   gre   dia   dig   rand   ...   exp   dea   idea   

原文地址:http://www.cnblogs.com/KennyRom/p/6292397.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!