Typecasting to 'int' in Python generating wrong result

前端 未结 2 967
庸人自扰
庸人自扰 2021-01-19 07:34

I tried performing following typecast operation in Python 3.3

int( 10**23 / 10 )

Output: 10000000000000000000000

And after in

2条回答
  •  不要未来只要你来
    2021-01-19 07:50

    You are doing floating-point division with the / operator. 10**24/10 happens to have an inexact integer representation.

    If you need an integer result, divide with //.

    >>> type(10**24/10)
    
    >>> type(10**24//10)
    
    

提交回复
热议问题