Skip to content

Commit 1487fc9

Browse files
committed
Added instruction that it's possible to import numpy twice, for compatibility.
1 parent be0e5c1 commit 1487fc9

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

02-loop.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,35 @@ but there must be a colon at the end of the line starting the loop,
135135
and we must indent anything we want to run inside the loop. Unlike many other languages, there is no
136136
command to signify the end of the loop body (e.g. end for); what is indented after the for statement belongs to the loop.
137137

138-
138+
> ## What's in a name? {.callout}
139+
> In the example above, the loop variable was given the name `char` as a mnemonic; it is short for 'character'. 'Char' is not a keyword in Python that pulls the characters from words or strings. In fact when a similar loop is run over a list rather than a word, the output would be each member of that list printed in order, rather than the characters.
140+
>~~~ {.python}
141+
>list = ['oxygen','nitrogen','argon']
142+
>for char in list:
143+
> print(char)
144+
>~~~
145+
>
146+
>~~~ {.output}
147+
>oxygen
148+
>nitrogen
149+
>argon
150+
>~~~
151+
> We can choose any name we want for variables. We might just as easily have chosen the name `banana` for the loop variable, as long as we use the same name when we invoke the variable inside the loop:
152+
>~~~ {.python}
153+
>word = 'oxygen'
154+
>for banana in word:
155+
> print(banana)
156+
>~~~
157+
>
158+
>~~~ {.output}
159+
>o
160+
>x
161+
>y
162+
>g
163+
>e
164+
>n
165+
>~~~
166+
> It is a good idea to choose variable names that are meaningful, otherwise it would be more difficult to understand what the loop is doing.
139167
140168
Here's another loop that repeatedly updates a variable:
141169

0 commit comments

Comments
 (0)