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

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
主站蜘蛛池模板: 棋牌| 廉江市| 荥经县| 姜堰市| 寿阳县| 江华| 三穗县| 高唐县| 大港区| 张掖市| 罗源县| 深水埗区| 昭通市| 静乐县| 永仁县| 娄烦县| 大新县| 大化| 乐平市| 民勤县| 读书| 蕲春县| 勐海县| 漾濞| 天镇县| 栾城县| 伊宁市| 右玉县| 华宁县| 股票| 木里| 昆山市| 宿州市| 孝昌县| 色达县| 贡觉县| 安乡县| 遂川县| 太湖县| 临汾市| 徐闻县|