Python/CheatSheet: Difference between revisions

From Wiki
No edit summary
No edit summary
Line 21: Line 21:




 
== While loops ==
 
 
 
<blockquote>
<blockquote>
<pre>
<pre>
 
while test:
    print (answer)
</pre>
</pre>
</blockquote>
</blockquote>




<blockquote>
<blockquote>
<pre>
<pre>
 
while True:
    print (answer)
    if answer == '2':
        break
</pre>
</pre>
</blockquote>
</blockquote>

Revision as of 11:27, 18 September 2017

If Then Else

if x < 0:
    print('Negative')
elif x == 0:
    print('Zero')
else:
    print('More')


For loops

for x in ['cat', 'dog', 'bird']:
    print (w)


While loops

while test:
    print (answer)


while True:
    print (answer)
    if answer == '2':
        break