官术网_书友最值得收藏!

Python operators

Python has the some numeric operators that you would expect; note that the truncating division, (//, also known as floor division) truncates the result to an integer and a floating point and return the integer value. The integer value is returned. The modulo (%) operator returns the remainder value in the division:

    >>> 1 + 2
3
>>> 2 - 1
1
>>> 1 * 5
5
>>> 5 / 1
5.0
>>> 5 // 2
2
>>> 5 % 2
1

There are also comparison operators:

    >>> a = 1
>>> b = 2
>>> a == b
False
>>> a > b
False
>>> a < b
True
>>> a <= b
True

We will also see two of the common membership operators to see whether an object is in a sequence type:

    >>> a = 'hello world'
>>> 'h' in a
True
>>> 'z' in a
False
>>> 'h' not in a
False
>>> 'z' not in a
True
主站蜘蛛池模板: 冀州市| 南丰县| 东安县| 维西| 信丰县| 英德市| 富平县| 宕昌县| 温宿县| 迭部县| 崇阳县| 灵丘县| 义马市| 汶上县| 岢岚县| 大竹县| 濉溪县| 凉山| 老河口市| 东阿县| 互助| 金川县| 顺平县| 衡南县| 班玛县| 齐齐哈尔市| 孙吴县| 天气| 五常市| 忻城县| 永德县| 师宗县| 定边县| 岢岚县| 嵊泗县| 西华县| 荔波县| 马公市| 沿河| 工布江达县| 五寨县|