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

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
主站蜘蛛池模板: 敖汉旗| 柞水县| 河南省| 民勤县| 莱西市| 徐水县| 信丰县| 贞丰县| 稷山县| 潮州市| 双流县| 大城县| 大余县| 南昌县| 济南市| 淮阳县| 丰都县| 吉隆县| 扎兰屯市| 湘潭县| 安阳市| 江门市| 乐山市| 芜湖县| 乌兰浩特市| 黔江区| 武穴市| 广宁县| 建平县| 湘西| 贵南县| 丹巴县| 天门市| 任丘市| 灵寿县| 鹤庆县| 华容县| 沽源县| 潢川县| 五常市| 霍林郭勒市|