Skip to content

Commit c1f29b9

Browse files
authored
Merge pull request #2817 from python-discord/swfarnsworth/tag-updates
Tag updates
2 parents 8f5a763 + 0ccd4fb commit c1f29b9

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

bot/resources/tags/codeblock.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
embed:
3-
title: "Formatting code on discord"
3+
title: "Formatting code on Discord"
44
---
55
Here's how to format Python code on Discord:
66

bot/resources/tags/equals-true.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
embed:
3+
title: "Comparisons to `True` and `False`"
4+
---
5+
It's tempting to think that if statements always need a comparison operator like `==` or `!=`, but this isn't true.
6+
If you're just checking if a value is truthy or falsey, you don't need `== True` or `== False`.
7+
```py
8+
# instead of this...
9+
if user_input.startswith('y') == True:
10+
my_func(user_input)
11+
12+
# ...write this
13+
if user_input.startswith('y'):
14+
my_func(user_input)
15+
16+
# for false conditions, instead of this...
17+
if user_input.startswith('y') == False:
18+
my_func(user_input)
19+
20+
# ...just use `not`
21+
if not user_input.startswith('y'):
22+
my_func(user_input)
23+
```
24+
This also applies to expressions that use `is True` or `is False`.

bot/resources/tags/range-len.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
embed:
33
title: "Pythonic way of iterating over ordered collections"
44
---
5-
Iterating over `range(len(...))` is a common approach to accessing each item in an ordered collection.
5+
Beginners often iterate over `range(len(...))` because they look like Java or C-style loops, but this is almost always a bad practice in Python.
66
```py
77
for i in range(len(my_list)):
88
do_something(my_list[i])
99
```
10-
The pythonic syntax is much simpler, and is guaranteed to produce elements in the same order:
10+
It's much simpler to iterate over the list (or other sequence) directly:
1111
```py
1212
for item in my_list:
1313
do_something(item)

0 commit comments

Comments
 (0)