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

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
主站蜘蛛池模板: 福海县| 临城县| 南陵县| 东宁县| 荣昌县| 太白县| 阿勒泰市| 鄂托克前旗| 石阡县| 台湾省| 黄浦区| 瑞金市| 婺源县| 庐江县| 大竹县| 新密市| 荔波县| 昂仁县| 本溪市| 天水市| 正安县| 威宁| 黄龙县| 阿拉善左旗| 博湖县| 柞水县| 西吉县| 九龙县| 页游| 新宁县| 青神县| 交城县| 牙克石市| 治县。| 永州市| 泸溪县| 耒阳市| 内丘县| 永仁县| 孟州市| 镇远县|