diff options
author | 2023-01-13 19:18:24 +0000 | |
---|---|---|
committer | 2023-01-13 19:18:24 +0000 | |
commit | 1b86216eacbd7752e956134461b819fbf2f4c9ee (patch) | |
tree | 3b237cbb7e8333c3d44243c9431e0c44efe1a773 | |
parent | Allow passing ful channel objects to check if the channel is ignored (diff) | |
parent | added under command Issue #2331 (#2354) (diff) |
Merge branch 'main' into allow-passing-channel-objets-when-checking-ignore
-rw-r--r-- | bot/resources/tags/underscore.md | 27 |
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). |