mvoorhie@virgil:~$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> "hello" 'hello' >>> hello Traceback (most recent call last): File "", line 1, in NameError: name 'hello' is not defined >>> 'hello' 'hello' >>> 'I say "hello"' 'I say "hello"' >>> """ ... this iss ... several ... lines ... """ '\nthis iss\nseveral\nlines\n' >>> 42 42 >>> 42.2 42.200000000000003 >>> 1+1 2 >>> 1-2 -1 >>> 3*5 15 >>> 5/3 1 >>> 5/3. 1.6666666666666667 >>> 5/float(3) 1.6666666666666667 >>> 2**3 8 >>> 2*3-(3+4)**2 -43 >>> "this is me looking at expresion data" 'this is me looking at expresion data' >>> # this is a comment ... >>> .02*(.03)/330./70. 2.5974025974025973e-08 >>> "%f" % (.02*(.03)/330./70.) '0.000000' >>> "%e" % (.02*(.03)/330./70.) '2.597403e-08' >>> (.02*(.03)/330./70.)/1e9 2.5974025974025972e-17 >>> (.02*(.03)/330./70.)*1e9 25.974025974025974 >>> b = 5 >>> "%f" % .02*(.03)/330./70. Traceback (most recent call last): File "", line 1, in TypeError: can't multiply sequence by non-int of type 'float' >>> "%f" % (.02*(.03)/330./70.) '0.000000' >>> a = 52 >>> a 52 >>> print a 52 >>> concentration = .02 >>> concentration 0.02 >>> b = concentration >>> b 0.02 >>> b = "concentration" >>> b 'concentration' >>> a = ["this", "is", "a", "list"] >>> a ['this', 'is', 'a', 'list'] >>> a[0] 'this' >>> a[1] 'is' >>> a[-1] 'list' >>> a[-2] 'a' >>> a[2] = 37 >>> a ['this', 'is', 37, 'list'] >>> b = a >>> b ['this', 'is', 37, 'list'] >>> a[2] = "a" >>> a ['this', 'is', 'a', 'list'] >>> b ['this', 'is', 'a', 'list'] >>> a[1:3] ['is', 'a'] >>> a ['this', 'is', 'a', 'list'] >>> a[1:] ['is', 'a', 'list'] >>> a[:3] ['this', 'is', 'a'] >>> a[:] ['this', 'is', 'a', 'list'] >>> b = a[:] >>> a ['this', 'is', 'a', 'list'] >>> b ['this', 'is', 'a', 'list'] >>> a[2] = 37 >>> a ['this', 'is', 37, 'list'] >>> b ['this', 'is', 'a', 'list'] >>> 23 + 23 46 >>> a = 3 >>> a += 2 >>> a 5 >>> a *= 2 >>> a 10 >>> a /= 2. >>> a 5.0 >>> "ATG" + "CAG" + "TGA" 'ATGCAGTGA' >>> a = "ATG" >>> a 'ATG' >>> a += "CAG" >>> a 'ATGCAG' >>> int(5/2.) 2 >>> print a ATGCAG >>> print a, b ATGCAG ['this', 'is', 'a', 'list'] >>> a == b False >>> a == a True >>> a == "ATGCAG" True >>> a = True >>> a True >>> a == True True >>> a == "True" False >>> a == 1 True >>> a != 1 False >>> 3 > 5 False >>> 3 < 5 True >>> 3 <= 5 True >>> 3 >= 5 False >>> a = "Test" >>> a == "Test" True >>> a == "test" False >>> a is "Test" True >>> a is not "Test" False >>> if(a == "Test"): ... print "it is!" ... else: ... print "it isn't" ... it is! >>> if(a == "Test"): ... print "it is!" ... print "it really really is!" ... else: ... print "nope" ... it is! it really really is! >>> a = 4 >>> if(a > 10): ... print "hi" ... elif(a > 8): ... print "no" ... elif(a > 6): ... print "hmmm" ... else: ... print "default" ... default >>> if(a > 10): ... print "hi" ... else: ... if(a > 6): ... print "hmm" ... else: ... print "default" ... default >>> if(a > 10): ... print "hi" ... else if(a > 3): File "", line 3 else if(a > 3): ^ SyntaxError: invalid syntax >>> a = [1,2,3,4,5] >>> for i in a: ... print i ... 1 2 3 4 5 >>> for i in a: ... print i**2 ... 1 4 9 16 25 >>> b = 0 >>> for i in a: ... b += i ... >>> b 15 >>> b = 0 >>> while (b < 100): ... b += 3 ... print b ... 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75 78 81 84 87 90 93 96 99 102 >>> while (b < 100): ... KeyboardInterrupt >>> b = 2 >>> while (b < 100): ... b = b**2 ... print b ... 4 16 256 >>> while (b > -1): ... b = b**2 ... ^CTraceback (most recent call last): File "", line 2, in KeyboardInterrupt >>> for i in range(0,103): ... print i ... 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 >>> range(0,10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(0,10,3) [0, 3, 6, 9] >>> range(10,0,-3) [10, 7, 4, 1] >>> for i in xrange(10): ... print i ... 0 1 2 3 4 5 6 7 8 9 >>> [2**i for i in range(5)] [1, 2, 4, 8, 16] >>> i 4 >>> a = [0,0,0,0,0] >>> a [0, 0, 0, 0, 0] >>> a = [0]*3 >>> a [0, 0, 0] >>> sum = __builtin__.sum Traceback (most recent call last): File "", line 1, in NameError: name '__builtin__' is not defined >>> sum = __builtins__.sum >>> sum(range(5)) 10 >>> import math >>> math.sqrt(25) 5.0 >>> math.log(8)/math.log(2) 3.0 >>> log2 = math.log(2) >>> math.log(25)/log2 4.6438561897747244 >>> def mean(x): ... """Return the mean of a list, x""" ... s = 0 ... c = 0 ... for i in x: ... s += i ... c += 1 ... >>> def mean(x): ... s = 0 ... c = 0 ... for i in x: ... s += i ... c += 1 ... return s/float(c) ... >>> mean(range(10)) 4.5 >>>