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

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
主站蜘蛛池模板: 绥棱县| 阿坝| 锦屏县| 三门峡市| 自治县| 远安县| 武宁县| 江西省| 临汾市| 栾城县| 大方县| 万全县| 禄劝| 来凤县| 潮安县| 特克斯县| 满洲里市| 女性| 刚察县| 东方市| 乌兰浩特市| 延边| 宽甸| 太谷县| 柳河县| 西华县| 阜平县| 鲁山县| 怀远县| 太白县| 商洛市| 碌曲县| 常州市| 合作市| 临猗县| 东方市| 榆树市| 堆龙德庆县| 丰台区| 新宁县| 宕昌县|