_ifloordiv_ ( a, b ) ¶Ī = ifloordiv(a, b) is equivalent to a //= b. _iconcat_ ( a, b ) ¶Ī = iconcat(a, b) is equivalent to a += b for a and b sequences. _iand_ ( a, b ) ¶Ī = iand(a, b) is equivalent to a &= b. _iadd_ ( a, b ) ¶Ī = iadd(a, b) is equivalent to a += b. Value is computed, but not assigned back to the input variable: The secondįor immutable targets such as strings, numbers, and tuples, the updated Listed below only do the first step, calling the in-place method. In those examples, note that when an in-place method is called, the computationĪnd assignment are performed in two separate steps. Z = operator.iadd(x, y) is equivalent to the compound statement Providing a more primitive access to in-place operators than the usual syntaxĭoes for example, the statement x += y is equivalent to Many operations have an “in-place” version. Python syntax and the functions in the operator module. This table shows how abstract operations correspond to operator symbols in the First try to return itsĪctual length, then an estimate using object._length_hint_(), andĭef methodcaller ( name, /, * args, ** kwargs ): def caller ( obj ): return getattr ( obj, name )( * args, ** kwargs ) return caller Mapping Operators to Functions ¶ Return an estimated length for the object obj. Return the index of the first of occurrence of b in a. Return the number of occurrences of b in a. Operations which work with sequences (some of them with mappings too) include: operator. Return the bitwise exclusive or of a and b. The mathematical and bitwise operations are the most numerous: operator. This isĮquivalent to using the bool constructor. Return True if obj is true, and False otherwise. The result is affected by the _bool_() and _not_() method for object instances only the interpreter core defines Truth tests, identity tests, and boolean operations: operator. The logical operations are also generally applicable to all objects, and support SeeĬomparisons for more information about rich comparisons. Or may not be interpretable as a Boolean value. Note that these functions can return any value, which may Specifically, lt(a, b) isĮquivalent to a b and ge(a, b) is equivalent to a >= b. Perform “rich comparisons” between a and b. The rich comparison operators they support: operator. The object comparison functions are useful for all objects, and are named after Operations, mathematical operations and sequence operations. The functions fall into categories that perform object comparisons, logical Without the double underscores are preferred for clarity. Many of these have a variant with the double underscores kept. Special methods, without the double underscores. For example, operator.add(x, y) isĮquivalent to the expression x+y. The operator module exports a set of efficient functions corresponding to Operator - Standard operators as functions ¶
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |