Difference between revisions of "Coursera - Getting started with Python"

From MyWiki
Jump to: navigation, search
(Created page with "# 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 +...")
 
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
# Python commands
+
'''Python commands'''
 
   
 
   
 
* quit()  or  ctrl + Z  or exit() -ends Python on Windows.
 
* 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 + D -Tells "End Of File" to Python on Mac and GNU/Linux.
 
* quit()  or  ctrl + C -Kills Python process 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'''
 +
<source lang="python">
 +
if (expression):
 +
  (command)
 +
elif (expression):
 +
  (command)
 +
else:
 +
  (command)
 +
</source>
 +
 +
'''Conditional Steps (Multi elif) - if ... elif .. else'''
 +
<source lang="python">
 +
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'
 +
</source>
 +
 +
'''Repeated steps - while'''
 +
<source lang="python">
 +
    while i < 6:
 +
        print "At the top i is %d" % i
 +
</source>
 +
'''Loop - for'''
 +
<source lang="python">
 +
    for (y) in (x):
 +
        (command)
 +
</source>
 +
 +
---

Latest revision as of 23:13, 13 November 2015

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'

Repeated steps - while

    while i < 6:
        print "At the top i is %d" % i

Loop - for

    for (y) in (x):
        (command)

---