aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar DivyanshuBist <[email protected]>2023-01-14 00:32:06 +0530
committerGravatar GitHub <[email protected]>2023-01-13 19:02:06 +0000
commit0ecc3ff6707a572f5823440aac1bd5c6a075982c (patch)
treeac8e9f7a8c83291f5cc60eae1fdd8943fa1dafaf
parentLink previous nomination threads to a user nomination's history (#2373) (diff)
added under command Issue #2331 (#2354)
* added under command Issue #2331 * hooks test * hooks tests * 2331_added_under_command * Update bot/resources/tags/under.md Co-authored-by: Xithrius <[email protected]> * Update bot/resources/tags/under.md Co-authored-by: Xithrius <[email protected]> * Update bot/resources/tags/under.md Co-authored-by: Xithrius <[email protected]> * Suggested Changes were committed Co-authored-by: Xithrius <[email protected]> * Update under.md * Update bot/resources/tags/under.md Co-authored-by: Vivek Ashokkumar <[email protected]> * updated bot\resources\tags\under.md * update bot\resources\tags\under.md * update bot\resources\tags\under.md * updated under.md * Update and rename under.md to underscore.md Co-authored-by: divyanshu <[email protected]> Co-authored-by: Xithrius <[email protected]> Co-authored-by: Vivek Ashokkumar <[email protected]> Co-authored-by: wookie184 <[email protected]>
-rw-r--r--bot/resources/tags/underscore.md27
1 files changed, 27 insertions, 0 deletions
diff --git a/bot/resources/tags/underscore.md b/bot/resources/tags/underscore.md
new file mode 100644
index 000000000..4da2e86ca
--- /dev/null
+++ b/bot/resources/tags/underscore.md
@@ -0,0 +1,27 @@
+---
+aliases: ["under"]
+embed:
+ title: "Meanings of Underscores in Identifier Names"
+---
+
+• `__name__`: Used to implement special behaviour, such as the `+` operator for classes with the `__add__` method. [More info](https://dbader.org/blog/python-dunder-methods)
+• `_name`: Indicates that a variable is "private" and should only be used by the class or module that defines it
+• `name_`: Used to avoid naming conflicts. For example, as `class` is a keyword, you could call a variable `class_` instead
+• `__name`: Causes the name to be "mangled" if defined inside a class. [More info](https://docs.python.org/3/tutorial/classes.html#private-variables)
+
+A single underscore, **`_`**, has multiple uses:
+• To indicate an unused variable, e.g. in a for loop if you don't care which iteration you are on
+```python
+for _ in range(10):
+ print("Hello World")
+```
+• In the REPL, where the previous result is assigned to the variable `_`
+```python
+>>> 1 + 1 # Evaluated and stored in `_`
+ 2
+>>> _ + 3 # Take the previous result and add 3
+ 5
+```
+• In integer literals, e.g. `x = 1_500_000` can be written instead of `x = 1500000` to improve readability
+
+See also ["Reserved classes of identifiers"](https://docs.python.org/3/reference/lexical_analysis.html#reserved-classes-of-identifiers) in the Python docs, and [this more detailed guide](https://dbader.org/blog/meaning-of-underscores-in-python).