aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/resources/tags/equals-true.md24
1 files changed, 24 insertions, 0 deletions
diff --git a/bot/resources/tags/equals-true.md b/bot/resources/tags/equals-true.md
new file mode 100644
index 000000000..d8e1a707e
--- /dev/null
+++ b/bot/resources/tags/equals-true.md
@@ -0,0 +1,24 @@
+---
+embed:
+ title: "Comparisons to `True` and `False`"
+---
+It's tempting to think that if statements always need a comparison operator like `==` or `!=`, but this isn't true.
+If you're just checking if a value is truthy or falsey, you don't need `== True` or `== False`.
+```py
+# instead of this...
+if user_input.startswith('y') == True:
+ my_func(user_input)
+
+# ...write this
+if user_input.startswith('y'):
+ my_func(user_input)
+
+# for false conditions, instead of this...
+if user_input.startswith('y') == False:
+ my_func(user_input)
+
+# ...just use `not`
+if not user_input.startswith('y'):
+ my_func(user_input)
+```
+This also applies to expressions that use `is True` or `is False`.