zoukankan      html  css  js  c++  java
  • python 内建函数功能函数 abs() coerce() divmod() round() pow()

    >>> abs(-1)
    1
    >>> abs(10.)  
    10.0
    >>> abs(1.2-2.1j)
    2.4186773244895647
    >>> abs(0.22-0.77)
    0.55
    >>> coerce(1,2)
    (1, 2)
    >>> 
    >>> coerce(1.3,134L)
    (1.3, 134.0)
    >>> 
    >>> coerce(1,134L)
    (1L, 134L)
    >>> coerce(1.23-41j,134L)
    ((1.23-41j), (134+0j))
    >>> 
    >>> divmod(10,3)
    (3, 1)
    >>> divmod(3,10)
    (0, 3)
    >>> divmod(10,2.5)
    (4.0, 0.0)
    >>> divmod(2.5,10)
    (0.0, 2.5)
    >>> divmod(2+1j,0.5-1j)
    ((-0+0j), (2+1j))
    >>> 
    >>> pow(2,5)
    32
    >>> pow(5,2)
    25
    >>> pow(1+1j,3)
    (-2+2j)
    >>> 
    >>> round(3)
    3.0
    >>> round(3.45)
    3.0
    >>> round(3.4999,1)
    3.5
    >>> import math
    >>> for eachnum in range(10):
     print round(math.pi,eachnum)

     
    3.0
    3.1
    3.14
    3.142
    3.1416
    3.14159
    3.141593
    3.1415927
    3.14159265
    3.141592654
    >>> round(-3.49,1)
    -3.5
    >>> round(-3.49)
    -3.0
    >>> round(0.5)
    1.0
    >>> round(-0.5)
    -1.0
    >>>

    abs():返回参数的绝对值

    coece():数据类型转换函数,返回一个包含类型转换完毕的两个数值元素的元组

    divmod():内建函数把除数和余数运算结果结合起来,返回一个包含商和余数的元组。

    round():用于对浮点数进行四舍五入运算

    pow():进行指数运算

     
     
  • 相关阅读:
    hdoj:2075
    hdoj:2072
    hdoj:2071
    hdoj:2070
    hdoj:2069
    test001
    hdoj:2067
    hdoj:2061
    hdoj:2058
    hdoj:2057
  • 原文地址:https://www.cnblogs.com/zknublx/p/5946107.html
Copyright © 2011-2022 走看看