BarCampGrandRapids4Python


 * 1) getting started

print 3

barcamp = "awesome" print barcamp

if ("awe" in barcamp    or "foo" in awesome): print barcamp[1:5] print barcamp[-1] print barcamp[:10]

print len([1,                2, 3, 4])

a = """ multi line comments """ print a

def calculate(x, y, crazy_mode=False, *args, **kwargs): """ this is a boring example""" if crazy_mode: return x*y + 44 else: return x-y + 3258

print calculate(1,2) print calculate(1,2,True) print calculate(1,2,crazy_mode=True)

print calculate print calculate.__doc__

for x in range(1,5): print x

for x in [1,2,3,4,5,6][::2]: print "we've got %s here %s" % (x, x+1) #print "we've got " + x

if 1 < 3 > 2: print "hey that makes sense!" d = {'a': 1, 'b': 2, 'c': 3, 'd': 4, }
 * 1) not:
 * 2) (1 > 3 ) > 2
 * 3) (True) > 2
 * 4) 1 > 2
 * 5) False

print d['a'] if 'e' in d:   print d['e'] print d.get('e') print d.get('e',999)
 * 1) print d['e']

for x in (value*2 for (key,value) in d.iteritems): print x
 * 1) print dict((k,v) for (k,v) in d.iteritems if k !='b')

""" python.org docs.python.org pypi.python.org rosettacode.org """