print 'In %d days I have eaten %g %s.' % (2, 3.5, 'lobsters') type("Go Red Sox!") print("Go Red Sox!") print "Wally the Green Monster" dir("Three strikes and you're out!") type(__builtins__) print dir(__builtins__) def new_world(): return 'Hello world!' print new_world() def squared(x): """ Return the square of a value """ return x ** 2 print squared(4) def love_chocolate(N): """ A function to explain how much I love chocolate """ print 'I' + ' love '*N + ' chocolate' love_chocolate(3) print "Does squared have a docstring?", squared.__doc__ != None print "Does love_chocolate have a docstring?", love_chocolate.__doc__ != None def squaredShifted(x, shift = 10): return shift + (x ** 2) squaredShifted(5, 20) def fact(n): if n ==0: return 1 else: recurse = fact(n-1) result = recurse * n return result fact(4) f = lambda x: x**2 f(3) x = 1 if x == 0: print 'x is equal to 0' else: print 'x is not equal to 0' if x == 0: pass # ignore zeros if x > 0: if x < 10: print 'x is greater than 0 and less than 10' elif x >= 10: print 'x is greater than 0 and greater than or equal to 10' if x > 0 and x < 10: print 'x is bigger than 0 and less than 10' for i in range(4): print 'Hello world!' def countdown(n): while n > 0: print n n = n-1 print 'Blastoff!' countdown(3)