Skip to content

Commit de99b73

Browse files
authored
Chained comparisons in conditional.py. (huangsam#124)
* Chained comparisons in conditional.py. * Change in the range. * Adjust to fit the code coverage. * W291. * Does comments make any difference to codecov?
1 parent fc87853 commit de99b73

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ultimatepython/syntax/conditional.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ def main():
5050
ran_5 = True if x_add_two == 3 else False
5151
assert ran_5 is True
5252

53+
# Python is one of the few programming languages that allows chained
54+
# comparisons. This is useful for checking if a variable is within
55+
# a range of values. You can see that in this example, the expression
56+
# `0 < x_add_two < 2` is equivalent to `x_add_two > 0 and x_add_two < 2`
57+
ran_6 = False
58+
if 0 < x_add_two < 2:
59+
ran_6 = False # skip: if
60+
else:
61+
ran_6 = True # run
62+
assert ran_6 is True
63+
5364

5465
if __name__ == "__main__":
5566
main()

0 commit comments

Comments
 (0)