zoukankan      html  css  js  c++  java
  • Python number

    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
    

      

  • 相关阅读:
    jvm类加载
    SpringMVC拦截器踩坑日记
    ConcurrentHashMap源码
    HashMap源码
    Linux搭建数据质量监控 Griffin
    那些说代码管理不方便的,我估计是你不会用git(Git源码管理)
    VS2019 开发AngularJS(TypeScript)代码缩进处理
    Arraylist和Map哪个性能更好
    dynamics crm 团队及团队模板
    无法加载文件或程序集 PublicKeyToken=null'或其依赖之一,需要强名称的程序集
  • 原文地址:https://www.cnblogs.com/KennyRom/p/6292397.html
Copyright © 2011-2022 走看看