{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Python Operators\n", "\n", "The table below shows what built-in Python operators correspond to\n", "in Excel when excelbird objects are used in arithmetic python expressions,\n", "i.e. ``product = my_row * my_col``. These rules apply for **any** excelbird object that can handle expressions - **Cell, Col/Row, Frame/VFrame**\n", "\n", "> Excelbird tries to mimic Excel syntax wherever possible, but in a handful of cases\n", "> this cannot be done. The most common example is the array range operator, `:`.\n", "> Where in Excel you'd use `a:b`, in excelbird use `a >> b`\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "The following are the **same** in excelbird and Excel\n", "\n", "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
PythonExcel
`a > b``a > b`
`a >= b``a >= b`
`a + b``a + b`
`a & b``a & b`
`a - b``a - b`
`a * b``a * b`
`a / b``a / b`
`a ^ b``a ^ b`
\n", "
\n", "\n", "---\n", "\n", "The following are all **different** in excelbird and Excel\n", "\n", "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
PythonExcel
`a >> b``a : b`
`a == b``a = b`
`a != b``a <> b`
`a ** b``a ^ b`
`a | b``OR(a, b)`
`a % b``MOD(a, b)`
`a % a``a%`Notice same object is on each sides
`~ a``NOT(a)`
\n", "
\n", "\n", "---\n", "\n", "Built-in python functions work as well. **Note**: For `sum()`, you\n", "must place your element(s) inside a list, even if there is only one.\n", "\n", "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
PythonExcel
`sum(a)``N/A`Don't do this. Pass list instead
`sum([a])``SUM(a)`
`sum([a, b])``SUM(a, b)`
`round(a, 2)``ROUND(a, 2)`
`abs(a)``ABS(a)`
`math.trunc(a)``TRUNC(a)`
`math.floor(a)``FLOOR(a, 1)`Excel's floor takes extra param.
`math.ceil(a)``CEILING(a, 1)`Excel's ceiling takes extra param.
\n", "
\n", "\n", "---\n" ] } ], "metadata": { "kernelspec": { "display_name": "env", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.1" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "6ee8c39a5e4f5a5ffe92ac0abdca1f10885ded7e28c74450614be57680931831" } } }, "nbformat": 4, "nbformat_minor": 2 }