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

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
主站蜘蛛池模板: 宜都市| 海南省| 民丰县| 阿克苏市| 肃北| 东莞市| 海林市| 新和县| 池州市| 新闻| 冕宁县| 凤城市| 秭归县| 安龙县| 白玉县| 灵丘县| 宝丰县| 犍为县| 营口市| 如东县| 老河口市| 永善县| 广元市| 乐陵市| 五指山市| 普宁市| 余江县| 花垣县| 西畴县| 昆山市| 嵊州市| 射阳县| 集贤县| 溧阳市| 西宁市| 稻城县| 将乐县| 屯留县| 商洛市| 象州县| 沂水县|