Coursera - Getting started with Python

From MyWiki
Revision as of 23:08, 13 November 2015 by George2 (Talk | contribs)

Jump to: navigation, search

Python commands

  • quit() or ctrl + Z or exit() -ends Python on Windows.
  • quit() or ctrl + D -Tells "End Of File" to Python on Mac and GNU/Linux.
  • quit() or ctrl + C -Kills Python process on Mac and GNU/Linux.

Conditional Steps, repeated steps, loop

Conditional Steps - if ... elif .. else

if (expression):
   (command)
elif (expression):
   (command)
else:
   (command)

Conditional Steps (Multi elif) - if ... elif .. else

if x < 0:
   x = 0
   print 'negative changed to zero'
elif x == 0:
   print 'zero'
elif x == 1:
   print 'single'
elif x == 2:
   print 'double'
else:
   print 'more'