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

Arithmetic in python2

时间:2016-01-29 21:14:21      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

Division and real division

>>> 1/2
0
>>> from __future__ import division
>>> 1/2
0.5
>>> 1//2
0

Comparison

>>> 1 > 2 > 3
False
>>> 3 > 2 > 1
True
>>> cmp(1,4)
-1

Numericla factory functions

>>> bool(0)
False
>>> bool(0)
True
>>> int(12332)
12332
>>> int(0xfff, base=16)
4095
>>> long(0xffffffff, base=16)
4294967295L
>>> float(1.23333)
1.23333
>>> float(123)
123.0
>>> complex(1,2)
(1+2j)

Coerce()

>>> help(coerce)
Help on built-in function coerce in module __builtin__:

coerce(...)
    coerce(x, y) -> (x1, y1)
    
    Return a tuple consisting of the two numeric arguments converted to
    a common type, using the same rules as used by arithmetic operations.
    If coercion is not possible, raise TypeError.

 

Arithmetic in python2

标签:

原文地址:http://www.cnblogs.com/ch3cooh/p/python-arithmetic.html

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