Python: int(3.0) = 2

后端 未结 1 924
礼貌的吻别
礼貌的吻别 2021-01-25 14:53

Observe the following python program

def goo(y,x):
    y = float(y)
    x = float(x)
    yup = (y - x - 1) / x
    yup = str(yup)
    yup = yup.split(\".\")
             


        
相关标签:
1条回答
  • 2021-01-25 15:43

    The default for the print statement is to round the value to the nearest. int() truncates.

    >>> print 2.99999999999999
    3.0
    >>> print int(2.99999999999999)
    2
    

    If you want to see a more exact representation, use repr.

    >>> print repr(2.9999999999999)
    2.9999999999999
    
    0 讨论(0)
提交回复
热议问题