X7ROOT File Manager
Current Path:
/usr/share/doc/python3-docs/html/library
usr
/
share
/
doc
/
python3-docs
/
html
/
library
/
π
..
π
2to3.html
(60.26 KB)
π
__future__.html
(15.42 KB)
π
__main__.html
(8.81 KB)
π
_dummy_thread.html
(8.98 KB)
π
_thread.html
(22.06 KB)
π
abc.html
(40.42 KB)
π
aifc.html
(27.46 KB)
π
allos.html
(31.48 KB)
π
archiving.html
(11.71 KB)
π
argparse.html
(268.54 KB)
π
array.html
(32.76 KB)
π
ast.html
(38.67 KB)
π
asynchat.html
(31.78 KB)
π
asyncio-dev.html
(50.65 KB)
π
asyncio-eventloop.html
(108.61 KB)
π
asyncio-eventloops.html
(32.25 KB)
π
asyncio-protocol.html
(85.38 KB)
π
asyncio-queue.html
(23.4 KB)
π
asyncio-stream.html
(59.58 KB)
π
asyncio-subprocess.html
(56.66 KB)
π
asyncio-sync.html
(34.84 KB)
π
asyncio-task.html
(82 KB)
π
asyncio.html
(27.37 KB)
π
asyncore.html
(41.71 KB)
π
atexit.html
(18 KB)
π
audioop.html
(34.61 KB)
π
base64.html
(35.6 KB)
π
bdb.html
(42.41 KB)
π
binary.html
(12.42 KB)
π
binascii.html
(24.17 KB)
π
binhex.html
(11.4 KB)
π
bisect.html
(25 KB)
π
builtins.html
(11.33 KB)
π
bz2.html
(32.58 KB)
π
calendar.html
(38.61 KB)
π
cgi.html
(54.57 KB)
π
cgitb.html
(12.47 KB)
π
chunk.html
(16.48 KB)
π
cmath.html
(33.37 KB)
π
cmd.html
(42.78 KB)
π
code.html
(27.23 KB)
π
codecs.html
(130.93 KB)
π
codeop.html
(13.97 KB)
π
collections.abc.html
(59.48 KB)
π
collections.html
(151.31 KB)
π
colorsys.html
(12.33 KB)
π
compileall.html
(27.6 KB)
π
concurrency.html
(20.71 KB)
π
concurrent.futures.html
(59.24 KB)
π
concurrent.html
(7.77 KB)
π
configparser.html
(137.75 KB)
π
constants.html
(17.09 KB)
π
contextlib.html
(86.72 KB)
π
copy.html
(13.52 KB)
π
copyreg.html
(14.38 KB)
π
crypt.html
(19.85 KB)
π
crypto.html
(10.66 KB)
π
csv.html
(67.42 KB)
π
ctypes.html
(258.33 KB)
π
curses.ascii.html
(24.61 KB)
π
curses.html
(171.44 KB)
π
curses.panel.html
(16.31 KB)
π
custominterp.html
(8.53 KB)
π
datatypes.html
(23.39 KB)
π
datetime.html
(299.25 KB)
π
dbm.html
(42.11 KB)
π
debug.html
(13.66 KB)
π
decimal.html
(228.01 KB)
π
development.html
(24.53 KB)
π
difflib.html
(93.9 KB)
π
dis.html
(103.7 KB)
π
distribution.html
(10.26 KB)
π
distutils.html
(10.63 KB)
π
doctest.html
(175.54 KB)
π
dummy_threading.html
(9.1 KB)
π
email.charset.html
(25.81 KB)
π
email.compat32-message.html
(84.13 KB)
π
email.contentmanager.html
(29.32 KB)
π
email.encoders.html
(13.92 KB)
π
email.errors.html
(19.24 KB)
π
email.examples.html
(56.52 KB)
π
email.generator.html
(40.82 KB)
π
email.header.html
(30.49 KB)
π
email.headerregistry.html
(56.32 KB)
π
email.html
(27.09 KB)
π
email.iterators.html
(13.21 KB)
π
email.message.html
(85.17 KB)
π
email.mime.html
(35.24 KB)
π
email.parser.html
(46.32 KB)
π
email.policy.html
(73.48 KB)
π
email.util.html
(33.06 KB)
π
ensurepip.html
(18.26 KB)
π
enum.html
(130.81 KB)
π
errno.html
(40.36 KB)
π
exceptions.html
(83.16 KB)
π
faulthandler.html
(22.85 KB)
π
fcntl.html
(26.68 KB)
π
filecmp.html
(24.45 KB)
π
fileformats.html
(10.87 KB)
π
fileinput.html
(29.33 KB)
π
filesys.html
(13.1 KB)
π
fnmatch.html
(16.59 KB)
π
formatter.html
(36.78 KB)
π
fpectl.html
(17.13 KB)
π
fractions.html
(29.22 KB)
π
frameworks.html
(13.16 KB)
π
ftplib.html
(53.15 KB)
π
functional.html
(8.79 KB)
π
functions.html
(196.76 KB)
π
functools.html
(63.43 KB)
π
gc.html
(28.83 KB)
π
getopt.html
(24.76 KB)
π
getpass.html
(11.78 KB)
π
gettext.html
(74.84 KB)
π
glob.html
(18 KB)
π
grp.html
(12.09 KB)
π
gzip.html
(31.9 KB)
π
hashlib.html
(77.69 KB)
π
heapq.html
(34.7 KB)
π
hmac.html
(17.41 KB)
π
html.entities.html
(11.09 KB)
π
html.html
(10.85 KB)
π
html.parser.html
(40.86 KB)
π
http.client.html
(63.72 KB)
π
http.cookiejar.html
(93.94 KB)
π
http.cookies.html
(38.41 KB)
π
http.html
(36.72 KB)
π
http.server.html
(56.83 KB)
π
i18n.html
(10.22 KB)
π
idle.html
(47.28 KB)
π
imaplib.html
(65.76 KB)
π
imghdr.html
(13.14 KB)
π
imp.html
(47.02 KB)
π
importlib.html
(169.05 KB)
π
index.html
(66.18 KB)
π
inspect.html
(127.3 KB)
π
internet.html
(30.36 KB)
π
intro.html
(9.67 KB)
π
io.html
(119.81 KB)
π
ipaddress.html
(103.39 KB)
π
ipc.html
(32.95 KB)
π
itertools.html
(129.71 KB)
π
json.html
(79.18 KB)
π
keyword.html
(8.71 KB)
π
language.html
(13.33 KB)
π
linecache.html
(13.18 KB)
π
locale.html
(60.1 KB)
π
logging.config.html
(83.49 KB)
π
logging.handlers.html
(109.76 KB)
π
logging.html
(131.69 KB)
π
lzma.html
(55.16 KB)
π
macpath.html
(9.04 KB)
π
mailbox.html
(153.63 KB)
π
mailcap.html
(14.33 KB)
π
markup.html
(18.9 KB)
π
marshal.html
(17.89 KB)
π
math.html
(52.4 KB)
π
mimetypes.html
(30.67 KB)
π
misc.html
(7.93 KB)
π
mm.html
(9.79 KB)
π
mmap.html
(33.49 KB)
π
modulefinder.html
(18.12 KB)
π
modules.html
(10.66 KB)
π
msilib.html
(55.86 KB)
π
msvcrt.html
(21.47 KB)
π
multiprocessing.html
(356.92 KB)
π
netdata.html
(17.06 KB)
π
netrc.html
(14.23 KB)
π
nis.html
(11.39 KB)
π
nntplib.html
(67.97 KB)
π
numbers.html
(40.46 KB)
π
numeric.html
(15.17 KB)
π
operator.html
(79.55 KB)
π
optparse.html
(244.08 KB)
π
os.html
(388.71 KB)
π
os.path.html
(52.56 KB)
π
ossaudiodev.html
(46.82 KB)
π
othergui.html
(10.02 KB)
π
parser.html
(41.41 KB)
π
pathlib.html
(113.99 KB)
π
pdb.html
(51.43 KB)
π
persistence.html
(14.92 KB)
π
pickle.html
(112.36 KB)
π
pickletools.html
(16.69 KB)
π
pipes.html
(15.62 KB)
π
pkgutil.html
(31.13 KB)
π
platform.html
(32.94 KB)
π
plistlib.html
(28.6 KB)
π
poplib.html
(30.21 KB)
π
posix.html
(17.2 KB)
π
pprint.html
(40.99 KB)
π
profile.html
(70.16 KB)
π
pty.html
(17.18 KB)
π
pwd.html
(12.79 KB)
π
py_compile.html
(15.14 KB)
π
pyclbr.html
(16.13 KB)
π
pydoc.html
(15.62 KB)
π
pyexpat.html
(86.85 KB)
π
python.html
(16.73 KB)
π
queue.html
(27.54 KB)
π
quopri.html
(13.53 KB)
π
random.html
(59.22 KB)
π
re.html
(186.7 KB)
π
readline.html
(41.15 KB)
π
reprlib.html
(24.38 KB)
π
resource.html
(35.7 KB)
π
rlcompleter.html
(14.05 KB)
π
runpy.html
(25.98 KB)
π
sched.html
(19.56 KB)
π
secrets.html
(24.15 KB)
π
select.html
(61.35 KB)
π
selectors.html
(35 KB)
π
shelve.html
(28.1 KB)
π
shlex.html
(47.83 KB)
π
shutil.html
(72.47 KB)
π
signal.html
(53.77 KB)
π
site.html
(31.49 KB)
π
smtpd.html
(35.05 KB)
π
smtplib.html
(66.83 KB)
π
sndhdr.html
(12.15 KB)
π
socket.html
(191.48 KB)
π
socketserver.html
(80 KB)
π
spwd.html
(12.04 KB)
π
sqlite3.html
(158.08 KB)
π
ssl.html
(260.08 KB)
π
stat.html
(43.67 KB)
π
statistics.html
(48.88 KB)
π
stdtypes.html
(454.74 KB)
π
string.html
(93.03 KB)
π
stringprep.html
(18.22 KB)
π
struct.html
(49.9 KB)
π
subprocess.html
(138.6 KB)
π
sunau.html
(31.01 KB)
π
superseded.html
(13.46 KB)
π
symbol.html
(8.64 KB)
π
symtable.html
(25.5 KB)
π
sys.html
(138.35 KB)
π
sysconfig.html
(29.55 KB)
π
syslog.html
(20.53 KB)
π
tabnanny.html
(11.98 KB)
π
tarfile.html
(94.49 KB)
π
telnetlib.html
(29.7 KB)
π
tempfile.html
(40.42 KB)
π
termios.html
(17.75 KB)
π
test.html
(76.71 KB)
π
text.html
(13.46 KB)
π
textwrap.html
(37.11 KB)
π
threading.html
(101.04 KB)
π
time.html
(77.76 KB)
π
timeit.html
(44.19 KB)
π
tk.html
(22.75 KB)
π
tkinter.html
(80.99 KB)
π
tkinter.scrolledtext.html
(9.72 KB)
π
tkinter.tix.html
(50.64 KB)
π
tkinter.ttk.html
(108.08 KB)
π
token.html
(22.13 KB)
π
tokenize.html
(31.4 KB)
π
trace.html
(28.46 KB)
π
traceback.html
(56.24 KB)
π
tracemalloc.html
(98.77 KB)
π
tty.html
(10.29 KB)
π
turtle.html
(244.5 KB)
π
types.html
(36.19 KB)
π
typing.html
(135.91 KB)
π
undoc.html
(8.97 KB)
π
unicodedata.html
(20.61 KB)
π
unittest.html
(244.81 KB)
π
unittest.mock-examples.html
(164.2 KB)
π
unittest.mock.html
(293.06 KB)
π
unix.html
(11.5 KB)
π
urllib.error.html
(14.13 KB)
π
urllib.html
(9.34 KB)
π
urllib.parse.html
(74.54 KB)
π
urllib.request.html
(173.05 KB)
π
urllib.robotparser.html
(16.75 KB)
π
uu.html
(11.92 KB)
π
uuid.html
(31.21 KB)
π
venv.html
(72.18 KB)
π
warnings.html
(49.14 KB)
π
wave.html
(29.17 KB)
π
weakref.html
(63.76 KB)
π
webbrowser.html
(26.27 KB)
π
windows.html
(10.38 KB)
π
winreg.html
(65.17 KB)
π
winsound.html
(20.77 KB)
π
wsgiref.html
(92.28 KB)
π
xdrlib.html
(32.96 KB)
π
xml.dom.html
(95.28 KB)
π
xml.dom.minidom.html
(40.51 KB)
π
xml.dom.pulldom.html
(23.65 KB)
π
xml.etree.elementtree.html
(132.32 KB)
π
xml.html
(18.81 KB)
π
xml.sax.handler.html
(41.66 KB)
π
xml.sax.html
(24.92 KB)
π
xml.sax.reader.html
(44.79 KB)
π
xml.sax.utils.html
(16.53 KB)
π
xmlrpc.client.html
(70.26 KB)
π
xmlrpc.html
(8.33 KB)
π
xmlrpc.server.html
(48.04 KB)
π
zipapp.html
(44.05 KB)
π
zipfile.html
(78.16 KB)
π
zipimport.html
(22.51 KB)
π
zlib.html
(33.75 KB)
Editing: operator.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>10.3. operator β Standard operators as functions — Python 3.6.7 documentation</title> <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 3.6.7 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="next" title="11. File and Directory Access" href="filesys.html" /> <link rel="prev" title="10.2. functools β Higher-order functions and operations on callable objects" href="functools.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="https://docs.python.org/3/library/operator.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="filesys.html" title="11. File and Directory Access" accesskey="N">next</a> |</li> <li class="right" > <a href="functools.html" title="10.2. functools β Higher-order functions and operations on callable objects" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.6.7 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="functional.html" accesskey="U">10. Functional Programming Modules</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-operator"> <span id="operator-standard-operators-as-functions"></span><h1>10.3. <a class="reference internal" href="#module-operator" title="operator: Functions corresponding to the standard operators."><code class="xref py py-mod docutils literal notranslate"><span class="pre">operator</span></code></a> β Standard operators as functions<a class="headerlink" href="#module-operator" title="Permalink to this headline">ΒΆ</a></h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.6/Lib/operator.py">Lib/operator.py</a></p> <hr class="docutils" /> <p>The <a class="reference internal" href="#module-operator" title="operator: Functions corresponding to the standard operators."><code class="xref py py-mod docutils literal notranslate"><span class="pre">operator</span></code></a> module exports a set of efficient functions corresponding to the intrinsic operators of Python. For example, <code class="docutils literal notranslate"><span class="pre">operator.add(x,</span> <span class="pre">y)</span></code> is equivalent to the expression <code class="docutils literal notranslate"><span class="pre">x+y</span></code>. Many function names are those used for special methods, without the double underscores. For backward compatibility, many of these have a variant with the double underscores kept. The variants without the double underscores are preferred for clarity.</p> <p>The functions fall into categories that perform object comparisons, logical operations, mathematical operations and sequence operations.</p> <p>The object comparison functions are useful for all objects, and are named after the rich comparison operators they support:</p> <dl class="function"> <dt id="operator.lt"> <code class="descclassname">operator.</code><code class="descname">lt</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.lt" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.le"> <code class="descclassname">operator.</code><code class="descname">le</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.le" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.eq"> <code class="descclassname">operator.</code><code class="descname">eq</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.eq" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.ne"> <code class="descclassname">operator.</code><code class="descname">ne</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.ne" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.ge"> <code class="descclassname">operator.</code><code class="descname">ge</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.ge" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.gt"> <code class="descclassname">operator.</code><code class="descname">gt</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.gt" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__lt__"> <code class="descclassname">operator.</code><code class="descname">__lt__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__lt__" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__le__"> <code class="descclassname">operator.</code><code class="descname">__le__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__le__" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__eq__"> <code class="descclassname">operator.</code><code class="descname">__eq__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__eq__" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__ne__"> <code class="descclassname">operator.</code><code class="descname">__ne__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__ne__" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__ge__"> <code class="descclassname">operator.</code><code class="descname">__ge__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__ge__" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__gt__"> <code class="descclassname">operator.</code><code class="descname">__gt__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__gt__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Perform βrich comparisonsβ between <em>a</em> and <em>b</em>. Specifically, <code class="docutils literal notranslate"><span class="pre">lt(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre"><</span> <span class="pre">b</span></code>, <code class="docutils literal notranslate"><span class="pre">le(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre"><=</span> <span class="pre">b</span></code>, <code class="docutils literal notranslate"><span class="pre">eq(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">==</span> <span class="pre">b</span></code>, <code class="docutils literal notranslate"><span class="pre">ne(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">!=</span> <span class="pre">b</span></code>, <code class="docutils literal notranslate"><span class="pre">gt(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">></span> <span class="pre">b</span></code> and <code class="docutils literal notranslate"><span class="pre">ge(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">>=</span> <span class="pre">b</span></code>. Note that these functions can return any value, which may or may not be interpretable as a Boolean value. See <a class="reference internal" href="../reference/expressions.html#comparisons"><span class="std std-ref">Comparisons</span></a> for more information about rich comparisons.</p> </dd></dl> <p>The logical operations are also generally applicable to all objects, and support truth tests, identity tests, and boolean operations:</p> <dl class="function"> <dt id="operator.not_"> <code class="descclassname">operator.</code><code class="descname">not_</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.not_" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__not__"> <code class="descclassname">operator.</code><code class="descname">__not__</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__not__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return the outcome of <a class="reference internal" href="../reference/expressions.html#not"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">not</span></code></a> <em>obj</em>. (Note that there is no <a class="reference internal" href="#operator.__not__" title="operator.__not__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__not__()</span></code></a> method for object instances; only the interpreter core defines this operation. The result is affected by the <a class="reference internal" href="../reference/datamodel.html#object.__bool__" title="object.__bool__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__bool__()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#object.__len__" title="object.__len__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__len__()</span></code></a> methods.)</p> </dd></dl> <dl class="function"> <dt id="operator.truth"> <code class="descclassname">operator.</code><code class="descname">truth</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.truth" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <a class="reference internal" href="constants.html#True" title="True"><code class="xref py py-const docutils literal notranslate"><span class="pre">True</span></code></a> if <em>obj</em> is true, and <a class="reference internal" href="constants.html#False" title="False"><code class="xref py py-const docutils literal notranslate"><span class="pre">False</span></code></a> otherwise. This is equivalent to using the <a class="reference internal" href="functions.html#bool" title="bool"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a> constructor.</p> </dd></dl> <dl class="function"> <dt id="operator.is_"> <code class="descclassname">operator.</code><code class="descname">is_</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.is_" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">is</span> <span class="pre">b</span></code>. Tests object identity.</p> </dd></dl> <dl class="function"> <dt id="operator.is_not"> <code class="descclassname">operator.</code><code class="descname">is_not</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.is_not" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">is</span> <span class="pre">not</span> <span class="pre">b</span></code>. Tests object identity.</p> </dd></dl> <p>The mathematical and bitwise operations are the most numerous:</p> <dl class="function"> <dt id="operator.abs"> <code class="descclassname">operator.</code><code class="descname">abs</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.abs" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__abs__"> <code class="descclassname">operator.</code><code class="descname">__abs__</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__abs__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return the absolute value of <em>obj</em>.</p> </dd></dl> <dl class="function"> <dt id="operator.add"> <code class="descclassname">operator.</code><code class="descname">add</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.add" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__add__"> <code class="descclassname">operator.</code><code class="descname">__add__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__add__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">+</span> <span class="pre">b</span></code>, for <em>a</em> and <em>b</em> numbers.</p> </dd></dl> <dl class="function"> <dt id="operator.and_"> <code class="descclassname">operator.</code><code class="descname">and_</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.and_" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__and__"> <code class="descclassname">operator.</code><code class="descname">__and__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__and__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return the bitwise and of <em>a</em> and <em>b</em>.</p> </dd></dl> <dl class="function"> <dt id="operator.floordiv"> <code class="descclassname">operator.</code><code class="descname">floordiv</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.floordiv" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__floordiv__"> <code class="descclassname">operator.</code><code class="descname">__floordiv__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__floordiv__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">//</span> <span class="pre">b</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.index"> <code class="descclassname">operator.</code><code class="descname">index</code><span class="sig-paren">(</span><em>a</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.index" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__index__"> <code class="descclassname">operator.</code><code class="descname">__index__</code><span class="sig-paren">(</span><em>a</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__index__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <em>a</em> converted to an integer. Equivalent to <code class="docutils literal notranslate"><span class="pre">a.__index__()</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.inv"> <code class="descclassname">operator.</code><code class="descname">inv</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.inv" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.invert"> <code class="descclassname">operator.</code><code class="descname">invert</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.invert" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__inv__"> <code class="descclassname">operator.</code><code class="descname">__inv__</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__inv__" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__invert__"> <code class="descclassname">operator.</code><code class="descname">__invert__</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__invert__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return the bitwise inverse of the number <em>obj</em>. This is equivalent to <code class="docutils literal notranslate"><span class="pre">~obj</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.lshift"> <code class="descclassname">operator.</code><code class="descname">lshift</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.lshift" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__lshift__"> <code class="descclassname">operator.</code><code class="descname">__lshift__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__lshift__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <em>a</em> shifted left by <em>b</em>.</p> </dd></dl> <dl class="function"> <dt id="operator.mod"> <code class="descclassname">operator.</code><code class="descname">mod</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.mod" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__mod__"> <code class="descclassname">operator.</code><code class="descname">__mod__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__mod__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">%</span> <span class="pre">b</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.mul"> <code class="descclassname">operator.</code><code class="descname">mul</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.mul" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__mul__"> <code class="descclassname">operator.</code><code class="descname">__mul__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__mul__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">*</span> <span class="pre">b</span></code>, for <em>a</em> and <em>b</em> numbers.</p> </dd></dl> <dl class="function"> <dt id="operator.matmul"> <code class="descclassname">operator.</code><code class="descname">matmul</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.matmul" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__matmul__"> <code class="descclassname">operator.</code><code class="descname">__matmul__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__matmul__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">@</span> <span class="pre">b</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <dl class="function"> <dt id="operator.neg"> <code class="descclassname">operator.</code><code class="descname">neg</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.neg" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__neg__"> <code class="descclassname">operator.</code><code class="descname">__neg__</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__neg__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <em>obj</em> negated (<code class="docutils literal notranslate"><span class="pre">-obj</span></code>).</p> </dd></dl> <dl class="function"> <dt id="operator.or_"> <code class="descclassname">operator.</code><code class="descname">or_</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.or_" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__or__"> <code class="descclassname">operator.</code><code class="descname">__or__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__or__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return the bitwise or of <em>a</em> and <em>b</em>.</p> </dd></dl> <dl class="function"> <dt id="operator.pos"> <code class="descclassname">operator.</code><code class="descname">pos</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.pos" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__pos__"> <code class="descclassname">operator.</code><code class="descname">__pos__</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__pos__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <em>obj</em> positive (<code class="docutils literal notranslate"><span class="pre">+obj</span></code>).</p> </dd></dl> <dl class="function"> <dt id="operator.pow"> <code class="descclassname">operator.</code><code class="descname">pow</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.pow" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__pow__"> <code class="descclassname">operator.</code><code class="descname">__pow__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__pow__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">**</span> <span class="pre">b</span></code>, for <em>a</em> and <em>b</em> numbers.</p> </dd></dl> <dl class="function"> <dt id="operator.rshift"> <code class="descclassname">operator.</code><code class="descname">rshift</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.rshift" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__rshift__"> <code class="descclassname">operator.</code><code class="descname">__rshift__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__rshift__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <em>a</em> shifted right by <em>b</em>.</p> </dd></dl> <dl class="function"> <dt id="operator.sub"> <code class="descclassname">operator.</code><code class="descname">sub</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.sub" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__sub__"> <code class="descclassname">operator.</code><code class="descname">__sub__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__sub__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">-</span> <span class="pre">b</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.truediv"> <code class="descclassname">operator.</code><code class="descname">truediv</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.truediv" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__truediv__"> <code class="descclassname">operator.</code><code class="descname">__truediv__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__truediv__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">/</span> <span class="pre">b</span></code> where 2/3 is .66 rather than 0. This is also known as βtrueβ division.</p> </dd></dl> <dl class="function"> <dt id="operator.xor"> <code class="descclassname">operator.</code><code class="descname">xor</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.xor" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__xor__"> <code class="descclassname">operator.</code><code class="descname">__xor__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__xor__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return the bitwise exclusive or of <em>a</em> and <em>b</em>.</p> </dd></dl> <p>Operations which work with sequences (some of them with mappings too) include:</p> <dl class="function"> <dt id="operator.concat"> <code class="descclassname">operator.</code><code class="descname">concat</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.concat" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__concat__"> <code class="descclassname">operator.</code><code class="descname">__concat__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__concat__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">+</span> <span class="pre">b</span></code> for <em>a</em> and <em>b</em> sequences.</p> </dd></dl> <dl class="function"> <dt id="operator.contains"> <code class="descclassname">operator.</code><code class="descname">contains</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.contains" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__contains__"> <code class="descclassname">operator.</code><code class="descname">__contains__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__contains__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return the outcome of the test <code class="docutils literal notranslate"><span class="pre">b</span> <span class="pre">in</span> <span class="pre">a</span></code>. Note the reversed operands.</p> </dd></dl> <dl class="function"> <dt id="operator.countOf"> <code class="descclassname">operator.</code><code class="descname">countOf</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.countOf" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return the number of occurrences of <em>b</em> in <em>a</em>.</p> </dd></dl> <dl class="function"> <dt id="operator.delitem"> <code class="descclassname">operator.</code><code class="descname">delitem</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.delitem" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__delitem__"> <code class="descclassname">operator.</code><code class="descname">__delitem__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__delitem__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Remove the value of <em>a</em> at index <em>b</em>.</p> </dd></dl> <dl class="function"> <dt id="operator.getitem"> <code class="descclassname">operator.</code><code class="descname">getitem</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.getitem" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__getitem__"> <code class="descclassname">operator.</code><code class="descname">__getitem__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__getitem__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return the value of <em>a</em> at index <em>b</em>.</p> </dd></dl> <dl class="function"> <dt id="operator.indexOf"> <code class="descclassname">operator.</code><code class="descname">indexOf</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.indexOf" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return the index of the first of occurrence of <em>b</em> in <em>a</em>.</p> </dd></dl> <dl class="function"> <dt id="operator.setitem"> <code class="descclassname">operator.</code><code class="descname">setitem</code><span class="sig-paren">(</span><em>a</em>, <em>b</em>, <em>c</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.setitem" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__setitem__"> <code class="descclassname">operator.</code><code class="descname">__setitem__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em>, <em>c</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__setitem__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Set the value of <em>a</em> at index <em>b</em> to <em>c</em>.</p> </dd></dl> <dl class="function"> <dt id="operator.length_hint"> <code class="descclassname">operator.</code><code class="descname">length_hint</code><span class="sig-paren">(</span><em>obj</em>, <em>default=0</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.length_hint" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return an estimated length for the object <em>o</em>. First try to return its actual length, then an estimate using <a class="reference internal" href="../reference/datamodel.html#object.__length_hint__" title="object.__length_hint__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__length_hint__()</span></code></a>, and finally return the default value.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.4.</span></p> </div> </dd></dl> <p>The <a class="reference internal" href="#module-operator" title="operator: Functions corresponding to the standard operators."><code class="xref py py-mod docutils literal notranslate"><span class="pre">operator</span></code></a> module also defines tools for generalized attribute and item lookups. These are useful for making fast field extractors as arguments for <a class="reference internal" href="functions.html#map" title="map"><code class="xref py py-func docutils literal notranslate"><span class="pre">map()</span></code></a>, <a class="reference internal" href="functions.html#sorted" title="sorted"><code class="xref py py-func docutils literal notranslate"><span class="pre">sorted()</span></code></a>, <a class="reference internal" href="itertools.html#itertools.groupby" title="itertools.groupby"><code class="xref py py-meth docutils literal notranslate"><span class="pre">itertools.groupby()</span></code></a>, or other functions that expect a function argument.</p> <dl class="function"> <dt id="operator.attrgetter"> <code class="descclassname">operator.</code><code class="descname">attrgetter</code><span class="sig-paren">(</span><em>attr</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.attrgetter" title="Permalink to this definition">ΒΆ</a></dt> <dt> <code class="descclassname">operator.</code><code class="descname">attrgetter</code><span class="sig-paren">(</span><em>*attrs</em><span class="sig-paren">)</span></dt> <dd><p>Return a callable object that fetches <em>attr</em> from its operand. If more than one attribute is requested, returns a tuple of attributes. The attribute names can also contain dots. For example:</p> <ul class="simple"> <li>After <code class="docutils literal notranslate"><span class="pre">f</span> <span class="pre">=</span> <span class="pre">attrgetter('name')</span></code>, the call <code class="docutils literal notranslate"><span class="pre">f(b)</span></code> returns <code class="docutils literal notranslate"><span class="pre">b.name</span></code>.</li> <li>After <code class="docutils literal notranslate"><span class="pre">f</span> <span class="pre">=</span> <span class="pre">attrgetter('name',</span> <span class="pre">'date')</span></code>, the call <code class="docutils literal notranslate"><span class="pre">f(b)</span></code> returns <code class="docutils literal notranslate"><span class="pre">(b.name,</span> <span class="pre">b.date)</span></code>.</li> <li>After <code class="docutils literal notranslate"><span class="pre">f</span> <span class="pre">=</span> <span class="pre">attrgetter('name.first',</span> <span class="pre">'name.last')</span></code>, the call <code class="docutils literal notranslate"><span class="pre">f(b)</span></code> returns <code class="docutils literal notranslate"><span class="pre">(b.name.first,</span> <span class="pre">b.name.last)</span></code>.</li> </ul> <p>Equivalent to:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">attrgetter</span><span class="p">(</span><span class="o">*</span><span class="n">items</span><span class="p">):</span> <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">items</span><span class="p">):</span> <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">'attribute name must be a string'</span><span class="p">)</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">items</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="n">attr</span> <span class="o">=</span> <span class="n">items</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">def</span> <span class="nf">g</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span> <span class="k">return</span> <span class="n">resolve_attr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">attr</span><span class="p">)</span> <span class="k">else</span><span class="p">:</span> <span class="k">def</span> <span class="nf">g</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span> <span class="k">return</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">resolve_attr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">attr</span><span class="p">)</span> <span class="k">for</span> <span class="n">attr</span> <span class="ow">in</span> <span class="n">items</span><span class="p">)</span> <span class="k">return</span> <span class="n">g</span> <span class="k">def</span> <span class="nf">resolve_attr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">attr</span><span class="p">):</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">attr</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">"."</span><span class="p">):</span> <span class="n">obj</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span> <span class="k">return</span> <span class="n">obj</span> </pre></div> </div> </dd></dl> <dl class="function"> <dt id="operator.itemgetter"> <code class="descclassname">operator.</code><code class="descname">itemgetter</code><span class="sig-paren">(</span><em>item</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.itemgetter" title="Permalink to this definition">ΒΆ</a></dt> <dt> <code class="descclassname">operator.</code><code class="descname">itemgetter</code><span class="sig-paren">(</span><em>*items</em><span class="sig-paren">)</span></dt> <dd><p>Return a callable object that fetches <em>item</em> from its operand using the operandβs <a class="reference internal" href="#operator.__getitem__" title="operator.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a> method. If multiple items are specified, returns a tuple of lookup values. For example:</p> <ul class="simple"> <li>After <code class="docutils literal notranslate"><span class="pre">f</span> <span class="pre">=</span> <span class="pre">itemgetter(2)</span></code>, the call <code class="docutils literal notranslate"><span class="pre">f(r)</span></code> returns <code class="docutils literal notranslate"><span class="pre">r[2]</span></code>.</li> <li>After <code class="docutils literal notranslate"><span class="pre">g</span> <span class="pre">=</span> <span class="pre">itemgetter(2,</span> <span class="pre">5,</span> <span class="pre">3)</span></code>, the call <code class="docutils literal notranslate"><span class="pre">g(r)</span></code> returns <code class="docutils literal notranslate"><span class="pre">(r[2],</span> <span class="pre">r[5],</span> <span class="pre">r[3])</span></code>.</li> </ul> <p>Equivalent to:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">itemgetter</span><span class="p">(</span><span class="o">*</span><span class="n">items</span><span class="p">):</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">items</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="n">item</span> <span class="o">=</span> <span class="n">items</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">def</span> <span class="nf">g</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span> <span class="k">return</span> <span class="n">obj</span><span class="p">[</span><span class="n">item</span><span class="p">]</span> <span class="k">else</span><span class="p">:</span> <span class="k">def</span> <span class="nf">g</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span> <span class="k">return</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">obj</span><span class="p">[</span><span class="n">item</span><span class="p">]</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">items</span><span class="p">)</span> <span class="k">return</span> <span class="n">g</span> </pre></div> </div> <p>The items can be any type accepted by the operandβs <a class="reference internal" href="#operator.__getitem__" title="operator.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a> method. Dictionaries accept any hashable value. Lists, tuples, and strings accept an index or a slice:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">itemgetter</span><span class="p">(</span><span class="mi">1</span><span class="p">)(</span><span class="s1">'ABCDEFG'</span><span class="p">)</span> <span class="go">'B'</span> <span class="gp">>>> </span><span class="n">itemgetter</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">5</span><span class="p">)(</span><span class="s1">'ABCDEFG'</span><span class="p">)</span> <span class="go">('B', 'D', 'F')</span> <span class="gp">>>> </span><span class="n">itemgetter</span><span class="p">(</span><span class="nb">slice</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="kc">None</span><span class="p">))(</span><span class="s1">'ABCDEFG'</span><span class="p">)</span> <span class="go">'CDEFG'</span> </pre></div> </div> <p>Example of using <a class="reference internal" href="#operator.itemgetter" title="operator.itemgetter"><code class="xref py py-func docutils literal notranslate"><span class="pre">itemgetter()</span></code></a> to retrieve specific fields from a tuple record:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">inventory</span> <span class="o">=</span> <span class="p">[(</span><span class="s1">'apple'</span><span class="p">,</span> <span class="mi">3</span><span class="p">),</span> <span class="p">(</span><span class="s1">'banana'</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="p">(</span><span class="s1">'pear'</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="p">(</span><span class="s1">'orange'</span><span class="p">,</span> <span class="mi">1</span><span class="p">)]</span> <span class="gp">>>> </span><span class="n">getcount</span> <span class="o">=</span> <span class="n">itemgetter</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">getcount</span><span class="p">,</span> <span class="n">inventory</span><span class="p">))</span> <span class="go">[3, 2, 5, 1]</span> <span class="gp">>>> </span><span class="nb">sorted</span><span class="p">(</span><span class="n">inventory</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="n">getcount</span><span class="p">)</span> <span class="go">[('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]</span> </pre></div> </div> </dd></dl> <dl class="function"> <dt id="operator.methodcaller"> <code class="descclassname">operator.</code><code class="descname">methodcaller</code><span class="sig-paren">(</span><em>name</em><span class="optional">[</span>, <em>args...</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#operator.methodcaller" title="Permalink to this definition">ΒΆ</a></dt> <dd><p>Return a callable object that calls the method <em>name</em> on its operand. If additional arguments and/or keyword arguments are given, they will be given to the method as well. For example:</p> <ul class="simple"> <li>After <code class="docutils literal notranslate"><span class="pre">f</span> <span class="pre">=</span> <span class="pre">methodcaller('name')</span></code>, the call <code class="docutils literal notranslate"><span class="pre">f(b)</span></code> returns <code class="docutils literal notranslate"><span class="pre">b.name()</span></code>.</li> <li>After <code class="docutils literal notranslate"><span class="pre">f</span> <span class="pre">=</span> <span class="pre">methodcaller('name',</span> <span class="pre">'foo',</span> <span class="pre">bar=1)</span></code>, the call <code class="docutils literal notranslate"><span class="pre">f(b)</span></code> returns <code class="docutils literal notranslate"><span class="pre">b.name('foo',</span> <span class="pre">bar=1)</span></code>.</li> </ul> <p>Equivalent to:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">methodcaller</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="k">def</span> <span class="nf">caller</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span> <span class="k">return</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">name</span><span class="p">)(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="k">return</span> <span class="n">caller</span> </pre></div> </div> </dd></dl> <div class="section" id="mapping-operators-to-functions"> <span id="operator-map"></span><h2>10.3.1. Mapping Operators to Functions<a class="headerlink" href="#mapping-operators-to-functions" title="Permalink to this headline">ΒΆ</a></h2> <p>This table shows how abstract operations correspond to operator symbols in the Python syntax and the functions in the <a class="reference internal" href="#module-operator" title="operator: Functions corresponding to the standard operators."><code class="xref py py-mod docutils literal notranslate"><span class="pre">operator</span></code></a> module.</p> <table border="1" class="docutils"> <colgroup> <col width="26%" /> <col width="29%" /> <col width="45%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Operation</th> <th class="head">Syntax</th> <th class="head">Function</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>Addition</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">+</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">add(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-odd"><td>Concatenation</td> <td><code class="docutils literal notranslate"><span class="pre">seq1</span> <span class="pre">+</span> <span class="pre">seq2</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">concat(seq1,</span> <span class="pre">seq2)</span></code></td> </tr> <tr class="row-even"><td>Containment Test</td> <td><code class="docutils literal notranslate"><span class="pre">obj</span> <span class="pre">in</span> <span class="pre">seq</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">contains(seq,</span> <span class="pre">obj)</span></code></td> </tr> <tr class="row-odd"><td>Division</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">/</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">truediv(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-even"><td>Division</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">//</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">floordiv(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-odd"><td>Bitwise And</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">&</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">and_(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-even"><td>Bitwise Exclusive Or</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">^</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">xor(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-odd"><td>Bitwise Inversion</td> <td><code class="docutils literal notranslate"><span class="pre">~</span> <span class="pre">a</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">invert(a)</span></code></td> </tr> <tr class="row-even"><td>Bitwise Or</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">|</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">or_(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-odd"><td>Exponentiation</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">**</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">pow(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-even"><td>Identity</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">is</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">is_(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-odd"><td>Identity</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">is</span> <span class="pre">not</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">is_not(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-even"><td>Indexed Assignment</td> <td><code class="docutils literal notranslate"><span class="pre">obj[k]</span> <span class="pre">=</span> <span class="pre">v</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">setitem(obj,</span> <span class="pre">k,</span> <span class="pre">v)</span></code></td> </tr> <tr class="row-odd"><td>Indexed Deletion</td> <td><code class="docutils literal notranslate"><span class="pre">del</span> <span class="pre">obj[k]</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">delitem(obj,</span> <span class="pre">k)</span></code></td> </tr> <tr class="row-even"><td>Indexing</td> <td><code class="docutils literal notranslate"><span class="pre">obj[k]</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">getitem(obj,</span> <span class="pre">k)</span></code></td> </tr> <tr class="row-odd"><td>Left Shift</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre"><<</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">lshift(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-even"><td>Modulo</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">%</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">mod(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-odd"><td>Multiplication</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">*</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">mul(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-even"><td>Matrix Multiplication</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">@</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">matmul(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-odd"><td>Negation (Arithmetic)</td> <td><code class="docutils literal notranslate"><span class="pre">-</span> <span class="pre">a</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">neg(a)</span></code></td> </tr> <tr class="row-even"><td>Negation (Logical)</td> <td><code class="docutils literal notranslate"><span class="pre">not</span> <span class="pre">a</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">not_(a)</span></code></td> </tr> <tr class="row-odd"><td>Positive</td> <td><code class="docutils literal notranslate"><span class="pre">+</span> <span class="pre">a</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">pos(a)</span></code></td> </tr> <tr class="row-even"><td>Right Shift</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">>></span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">rshift(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-odd"><td>Slice Assignment</td> <td><code class="docutils literal notranslate"><span class="pre">seq[i:j]</span> <span class="pre">=</span> <span class="pre">values</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">setitem(seq,</span> <span class="pre">slice(i,</span> <span class="pre">j),</span> <span class="pre">values)</span></code></td> </tr> <tr class="row-even"><td>Slice Deletion</td> <td><code class="docutils literal notranslate"><span class="pre">del</span> <span class="pre">seq[i:j]</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">delitem(seq,</span> <span class="pre">slice(i,</span> <span class="pre">j))</span></code></td> </tr> <tr class="row-odd"><td>Slicing</td> <td><code class="docutils literal notranslate"><span class="pre">seq[i:j]</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">getitem(seq,</span> <span class="pre">slice(i,</span> <span class="pre">j))</span></code></td> </tr> <tr class="row-even"><td>String Formatting</td> <td><code class="docutils literal notranslate"><span class="pre">s</span> <span class="pre">%</span> <span class="pre">obj</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">mod(s,</span> <span class="pre">obj)</span></code></td> </tr> <tr class="row-odd"><td>Subtraction</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">-</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">sub(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-even"><td>Truth Test</td> <td><code class="docutils literal notranslate"><span class="pre">obj</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">truth(obj)</span></code></td> </tr> <tr class="row-odd"><td>Ordering</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre"><</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">lt(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-even"><td>Ordering</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre"><=</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">le(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-odd"><td>Equality</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">==</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">eq(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-even"><td>Difference</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">!=</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">ne(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-odd"><td>Ordering</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">>=</span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">ge(a,</span> <span class="pre">b)</span></code></td> </tr> <tr class="row-even"><td>Ordering</td> <td><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">></span> <span class="pre">b</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">gt(a,</span> <span class="pre">b)</span></code></td> </tr> </tbody> </table> </div> <div class="section" id="inplace-operators"> <h2>10.3.2. Inplace Operators<a class="headerlink" href="#inplace-operators" title="Permalink to this headline">ΒΆ</a></h2> <p>Many operations have an βin-placeβ version. Listed below are functions providing a more primitive access to in-place operators than the usual syntax does; for example, the <a class="reference internal" href="../glossary.html#term-statement"><span class="xref std std-term">statement</span></a> <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">+=</span> <span class="pre">y</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">=</span> <span class="pre">operator.iadd(x,</span> <span class="pre">y)</span></code>. Another way to put it is to say that <code class="docutils literal notranslate"><span class="pre">z</span> <span class="pre">=</span> <span class="pre">operator.iadd(x,</span> <span class="pre">y)</span></code> is equivalent to the compound statement <code class="docutils literal notranslate"><span class="pre">z</span> <span class="pre">=</span> <span class="pre">x;</span> <span class="pre">z</span> <span class="pre">+=</span> <span class="pre">y</span></code>.</p> <p>In those examples, note that when an in-place method is called, the computation and assignment are performed in two separate steps. The in-place functions listed below only do the first step, calling the in-place method. The second step, assignment, is not handled.</p> <p>For immutable targets such as strings, numbers, and tuples, the updated value is computed, but not assigned back to the input variable:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="s1">'hello'</span> <span class="gp">>>> </span><span class="n">iadd</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="s1">' world'</span><span class="p">)</span> <span class="go">'hello world'</span> <span class="gp">>>> </span><span class="n">a</span> <span class="go">'hello'</span> </pre></div> </div> <p>For mutable targets such as lists and dictionaries, the inplace method will perform the update, so no subsequent assignment is necessary:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'h'</span><span class="p">,</span> <span class="s1">'e'</span><span class="p">,</span> <span class="s1">'l'</span><span class="p">,</span> <span class="s1">'l'</span><span class="p">,</span> <span class="s1">'o'</span><span class="p">]</span> <span class="gp">>>> </span><span class="n">iadd</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="p">[</span><span class="s1">' '</span><span class="p">,</span> <span class="s1">'w'</span><span class="p">,</span> <span class="s1">'o'</span><span class="p">,</span> <span class="s1">'r'</span><span class="p">,</span> <span class="s1">'l'</span><span class="p">,</span> <span class="s1">'d'</span><span class="p">])</span> <span class="go">['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']</span> <span class="gp">>>> </span><span class="n">s</span> <span class="go">['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']</span> </pre></div> </div> <dl class="function"> <dt id="operator.iadd"> <code class="descclassname">operator.</code><code class="descname">iadd</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.iadd" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__iadd__"> <code class="descclassname">operator.</code><code class="descname">__iadd__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__iadd__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">iadd(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">+=</span> <span class="pre">b</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.iand"> <code class="descclassname">operator.</code><code class="descname">iand</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.iand" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__iand__"> <code class="descclassname">operator.</code><code class="descname">__iand__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__iand__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">iand(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">&=</span> <span class="pre">b</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.iconcat"> <code class="descclassname">operator.</code><code class="descname">iconcat</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.iconcat" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__iconcat__"> <code class="descclassname">operator.</code><code class="descname">__iconcat__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__iconcat__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">iconcat(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">+=</span> <span class="pre">b</span></code> for <em>a</em> and <em>b</em> sequences.</p> </dd></dl> <dl class="function"> <dt id="operator.ifloordiv"> <code class="descclassname">operator.</code><code class="descname">ifloordiv</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.ifloordiv" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__ifloordiv__"> <code class="descclassname">operator.</code><code class="descname">__ifloordiv__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__ifloordiv__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">ifloordiv(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">//=</span> <span class="pre">b</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.ilshift"> <code class="descclassname">operator.</code><code class="descname">ilshift</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.ilshift" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__ilshift__"> <code class="descclassname">operator.</code><code class="descname">__ilshift__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__ilshift__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">ilshift(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre"><<=</span> <span class="pre">b</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.imod"> <code class="descclassname">operator.</code><code class="descname">imod</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.imod" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__imod__"> <code class="descclassname">operator.</code><code class="descname">__imod__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__imod__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">imod(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">%=</span> <span class="pre">b</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.imul"> <code class="descclassname">operator.</code><code class="descname">imul</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.imul" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__imul__"> <code class="descclassname">operator.</code><code class="descname">__imul__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__imul__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">imul(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">*=</span> <span class="pre">b</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.imatmul"> <code class="descclassname">operator.</code><code class="descname">imatmul</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.imatmul" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__imatmul__"> <code class="descclassname">operator.</code><code class="descname">__imatmul__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__imatmul__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">imatmul(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">@=</span> <span class="pre">b</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <dl class="function"> <dt id="operator.ior"> <code class="descclassname">operator.</code><code class="descname">ior</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.ior" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__ior__"> <code class="descclassname">operator.</code><code class="descname">__ior__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__ior__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">ior(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">|=</span> <span class="pre">b</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.ipow"> <code class="descclassname">operator.</code><code class="descname">ipow</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.ipow" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__ipow__"> <code class="descclassname">operator.</code><code class="descname">__ipow__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__ipow__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">ipow(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">**=</span> <span class="pre">b</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.irshift"> <code class="descclassname">operator.</code><code class="descname">irshift</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.irshift" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__irshift__"> <code class="descclassname">operator.</code><code class="descname">__irshift__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__irshift__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">irshift(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">>>=</span> <span class="pre">b</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.isub"> <code class="descclassname">operator.</code><code class="descname">isub</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.isub" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__isub__"> <code class="descclassname">operator.</code><code class="descname">__isub__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__isub__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">isub(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">-=</span> <span class="pre">b</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.itruediv"> <code class="descclassname">operator.</code><code class="descname">itruediv</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.itruediv" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__itruediv__"> <code class="descclassname">operator.</code><code class="descname">__itruediv__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__itruediv__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">itruediv(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">/=</span> <span class="pre">b</span></code>.</p> </dd></dl> <dl class="function"> <dt id="operator.ixor"> <code class="descclassname">operator.</code><code class="descname">ixor</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.ixor" title="Permalink to this definition">ΒΆ</a></dt> <dt id="operator.__ixor__"> <code class="descclassname">operator.</code><code class="descname">__ixor__</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#operator.__ixor__" title="Permalink to this definition">ΒΆ</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">ixor(a,</span> <span class="pre">b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">^=</span> <span class="pre">b</span></code>.</p> </dd></dl> </div> </div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">10.3. <code class="docutils literal notranslate"><span class="pre">operator</span></code> β Standard operators as functions</a><ul> <li><a class="reference internal" href="#mapping-operators-to-functions">10.3.1. Mapping Operators to Functions</a></li> <li><a class="reference internal" href="#inplace-operators">10.3.2. Inplace Operators</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="functools.html" title="previous chapter">10.2. <code class="docutils literal notranslate"><span class="pre">functools</span></code> β Higher-order functions and operations on callable objects</a></p> <h4>Next topic</h4> <p class="topless"><a href="filesys.html" title="next chapter">11. File and Directory Access</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li> <a href="https://github.com/python/cpython/blob/3.6/Doc/library/operator.rst" rel="nofollow">Show Source </a> </li> </ul> </div> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="filesys.html" title="11. File and Directory Access" >next</a> |</li> <li class="right" > <a href="functools.html" title="10.2. functools β Higher-order functions and operations on callable objects" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.6.7 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="functional.html" >10. Functional Programming Modules</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 2001-2023, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Dec 18, 2023. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.6. </div> </body> </html>
Upload File
Create Folder