Skip to content

Commit

Permalink
Try to fix the build
Browse files Browse the repository at this point in the history
  • Loading branch information
s2t2 committed Aug 15, 2024
1 parent 8184ede commit c741b4d
Show file tree
Hide file tree
Showing 4 changed files with 309 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ open:

open-pdf:
open docs/_build/Intro-to-Python-Programming.pdf



render-fresh:
rm -rf docs/_build
rm -rf docs/.quarto
quarto render docs/
6 changes: 3 additions & 3 deletions docs/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ book:
repo-branch: main
repo-subdir: docs
repo-actions: [edit, issue, source]
downloads: [pdf, epub, docx]
#downloads: [pdf, epub, docx]

#cover-image: cover.png
#favicon: favicon.ico
Expand Down Expand Up @@ -221,5 +221,5 @@ format:
##number-sections: false
##number-depth: 1

pdf:
documentclass: scrreprt
#pdf:
# documentclass: scrreprt
2 changes: 1 addition & 1 deletion docs/index.qmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Welcome {.unnumbered}

![](./images/python-banner.jpeg){fig-align="center" fig-alt="Intro to Software Development in Python (banner image)"}
![](/images/python-banner.jpeg){fig-align="center" fig-alt="Intro to Software Development in Python (banner image)"}

Welcome to the \"Intro to Software Development in Python\" book (2024 edition, online)!

Expand Down
298 changes: 298 additions & 0 deletions docs/notes/python-lang/python-operators.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
{
"cells": [
{
"cell_type": "raw",
"metadata": {},
"source": [
"---\n",
"format:\n",
" html:\n",
" code-fold: false\n",
"execute:\n",
" cache: true\n",
"---"
],
"id": "5471fbfa"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Python Operators\n",
"\n",
"\n",
"We have seen examples of arithmetic operators, and the double equals sign, but let's cover a wide range of operators in Python.\n",
"\n",
"The [Python Operators page from W3 Schools](https://www.w3schools.com/python/python_operators.asp) provides an excellent overview. Contents copied below for reference.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"## Arithmetic Operators\n",
"\n",
"![Arithmetic Operators. Source: [W3 Schools](https://www.w3schools.com/python/python_operators.asp)](../../images/operators-arithmetic.png)\n",
"\n",
"Examples (with numbers):\n"
],
"id": "eca1ae91"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"print(2 + 10)\n",
"print(2 - 10)\n",
"print(2 * 10)\n",
"print(2 / 10)"
],
"id": "c3180287",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Comparison Operators\n",
"\n",
"![Comparison Operators. Source: [W3 Schools](https://www.w3schools.com/python/python_operators.asp)](../../images/operators-comparison.png)\n"
],
"id": "99e3a734"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"print(2 == 10)\n",
"print(2 != 10)\n",
"\n",
"print(2 < 10)\n",
"print(2 <= 10)\n",
"\n",
"print(2 > 10)\n",
"print(2 >= 10)"
],
"id": "9f21a4ea",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Assignment Operators\n",
"\n",
"![Assignment Operators. Source: [W3 Schools](https://www.w3schools.com/python/python_operators.asp)](../../images/operators-assignment.png)\n",
"\n",
"\n",
"Examples:\n"
],
"id": "573dd29e"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"x = 5\n",
"print(x)\n",
"\n",
"x = x + 1\n",
"print(x)\n",
"\n",
"x += 1\n",
"print(x)"
],
"id": "b22d17cb",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Membership Operators\n",
"\n",
"![Membership Operators. Source: [W3 Schools](https://www.w3schools.com/python/python_operators.asp)](../../images/operators-membership.png)\n",
"\n",
"\n",
"\n",
"Examples (with strings):\n"
],
"id": "9fd696f6"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"print(\"H\" in \"Hello World\")\n",
"print(\"H\" not in \"Hello World\")"
],
"id": "7d928c7e",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Examples (with lists):\n"
],
"id": "0828e571"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"print(5 in [1,2,5])\n",
"print(5 not in [1,2,5])"
],
"id": "10f1f03d",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Logical Operators\n",
"\n",
"![Logical Operators. Source: [W3 Schools](https://www.w3schools.com/python/python_operators.asp)](../../images/operators-logical.png)\n",
"\n",
"\n",
"Examples (for compound expressions):\n"
],
"id": "4caf5a2a"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"x = 5\n",
"\n",
"print(x > 0 and x > 20)\n",
"print(x > 0 or x > 20)"
],
"id": "9cb21788",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `and` operator will return `True` if BOTH sides are true.\n"
],
"id": "127b27e2"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"print(True and True)\n",
"print(True and False)\n",
"print(False and True)\n",
"print(False and False)"
],
"id": "424a1d0a",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `or` operator will return `True` if EITHER side is true.\n"
],
"id": "61e35461"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"print(True or True)\n",
"print(True or False)\n",
"print(False or True)\n",
"print(False or False)"
],
"id": "60ea2fb1",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Truthiness\n",
"\n",
"\n",
"Another way of using the `or` operator is within the concept of \"truthiness\".\n",
"\n",
"In this context, the `or` operator will return the first \"truthy\" value.\n",
"\n",
"\n",
"Values that are considered \"truthy\" are `True`, or any other object that is present or non-empty, or non-blank.\n",
"\n",
"Values that are considered \"falsy\" are `False`, `None`, empty string (`\"\"`), empty list (`[]`), etc.\n"
],
"id": "457776e1"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"0 or \"\" or [] or False or None or 4 or \"Hello World\" or True"
],
"id": "c4810d05",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this case, we see `4` returned because it is the first truthy value.\n",
"\n",
"In practice, we usually use \"truthiness\" to set a value if it is not null:\n"
],
"id": "e380c7c3"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"original = \"My Old Value\"\n",
"new = original or \"My New Value\"\n",
"print(new)"
],
"id": "8e5890ca",
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {},
"source": [
"original = None\n",
"new = original or \"My New Value\"\n",
"print(new)"
],
"id": "b9fb1b0e",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"language": "python",
"display_name": "Python 3 (ipykernel)"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit c741b4d

Please sign in to comment.