{
"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",
"| Python | \n",
"Excel | \n",
" | \n",
"
\n",
"\n",
"\n",
"\n",
"\n",
"| `a > b` | \n",
"`a > b` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `a >= b` | \n",
"`a >= b` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `a + b` | \n",
"`a + b` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `a & b` | \n",
"`a & b` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `a - b` | \n",
"`a - b` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `a * b` | \n",
"`a * b` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `a / b` | \n",
"`a / b` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `a ^ b` | \n",
"`a ^ b` | \n",
" | \n",
"
\n",
"\n",
"\n",
"
\n",
"
\n",
"\n",
"---\n",
"\n",
"The following are all **different** in excelbird and Excel\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"| Python | \n",
"Excel | \n",
" | \n",
"
\n",
"\n",
"\n",
"\n",
"\n",
"| `a >> b` | \n",
"`a : b` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `a == b` | \n",
"`a = b` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `a != b` | \n",
"`a <> b` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `a ** b` | \n",
"`a ^ b` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `a | b` | \n",
"`OR(a, b)` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `a % b` | \n",
"`MOD(a, b)` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `a % a` | \n",
"`a%` | \n",
"Notice same object is on each sides | \n",
"
\n",
"\n",
"\n",
"| `~ a` | \n",
"`NOT(a)` | \n",
" | \n",
"
\n",
"\n",
"\n",
"\n",
"
\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",
"| Python | \n",
"Excel | \n",
"
\n",
"\n",
"\n",
"\n",
"\n",
"| `sum(a)` | \n",
"`N/A` | \n",
"Don't do this. Pass list instead | \n",
"
\n",
"\n",
"\n",
"| `sum([a])` | \n",
"`SUM(a)` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `sum([a, b])` | \n",
"`SUM(a, b)` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `round(a, 2)` | \n",
"`ROUND(a, 2)` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `abs(a)` | \n",
"`ABS(a)` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `math.trunc(a)` | \n",
"`TRUNC(a)` | \n",
" | \n",
"
\n",
"\n",
"\n",
"| `math.floor(a)` | \n",
"`FLOOR(a, 1)` | \n",
"Excel's floor takes extra param. | \n",
"
\n",
"\n",
"\n",
"| `math.ceil(a)` | \n",
"`CEILING(a, 1)` | \n",
"Excel's ceiling takes extra param. | \n",
"
\n",
"\n",
"\n",
"\n",
"\n",
"
\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
}