Newbie Programming Mistakes: Difference between revisions

 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
If you have a bool, you can just use it instead of comparing to <code>true</code> or <code>false</code>:
If you have a bool, you can just use it instead of comparing to <code>true</code> or <code>false</code>:
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
# some code which produces a bool b
# some code which produces bool b
b = a > 5
b = a > 5
# return b == false
# return b == false
Line 24: Line 24:
a = np.arange(5)
a = np.arange(5)
b = np.arange(5)
b = np.arange(5)
# Bad
c = np.zeros(5)
c = np.zeros(5)
# Bad
for i in range(len(a)):
for i in range(len(a)):
   c[i] = a[i] + 5*b[i]
   c[i] = a[i] + 5*b[i]