Skip to content

Commit 71129fe

Browse files
committed
n00b-friendliness :DD
1 parent 2294f2c commit 71129fe

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

if.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ but it's not possible to create custom keywords. That's why keywords are
7373
usually used for "magic" things that would be difficult to do with just
7474
functions.
7575

76+
Also note that if statements check the condition once only, so if you
77+
set it to false later the if statement won't notice it.
78+
79+
```py
80+
>>> its_raining = True
81+
>>> if its_raining:
82+
... its_raining = False
83+
... print("It's not raining, but this runs anyway.")
84+
...
85+
It's not raining, but this runs anyway.
86+
>>>
87+
```
88+
7689
## Storing code in files
7790

7891
At this point it's easier to put your code into a file and use it
@@ -167,7 +180,20 @@ else:
167180
print("It's not raining.")
168181
```
169182

170-
By combining that with the input function we can make a program that
183+
The else part simply runs when the if statement doesn't run. It doesn't
184+
check the condition again.
185+
186+
```py
187+
>>> its_raining = True
188+
>>> if its_raining:
189+
... its_raining = False
190+
... else:
191+
... print("It's not raining, but this still doesn't run.")
192+
...
193+
>>>
194+
```
195+
196+
By combining `else` with the input function we can make a program that
171197
asks for a password and checks if it's correct.
172198

173199
```py

0 commit comments

Comments
 (0)