Home  >  Article  >  Backend Development  >  python core data types numeric types and collections

python core data types numeric types and collections

高洛峰
高洛峰Original
2017-03-09 09:51:151310browse

Related calculations

Operation Description Operation Description
x + y Addition x ** y Power
x - y Subtraction x % y Modulo (x mod y)
x * y Multiplication +x One-yuan addition
x / y Division (2.6 omit the decimal part) -y Uniary subtraction
x // y Truncation and division x if y else z Ternary expression

Comparison operation

#x << yx left shift y bitsx \ybitwise orx >> yx shifts right by y bitsx ^ yBitwise exclusive OR## x & y##Some notes on numbers
Operation Description Operation Description

bitwise AND ~x bitwise negation

is_integer

Test whether a floating point number is an integer official document


Numeric-related modules
math
,

randomint() and math.trunc() will omit the decimal part, the round() function can do rounding, math.floor is 2.7 The decimal place will be retained as 0 under 3.0, which has the same effect as int under 3.0
python3.0 no longer supports dictionary size comparison, you can use sorted(dict.items()) instead

Set


add() insert

update() union by position

remove() delete an item based on value


Why use a set?

Filter out duplicates

Record visited locations


The above is the detailed content of python core data types numeric types and collections. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn