-
-
Notifications
You must be signed in to change notification settings - Fork 691
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2817 from python-discord/swfarnsworth/tag-updates
Tag updates
- Loading branch information
Showing
3 changed files
with
27 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters