1. Open python. 2. >>> print("Hello World!") Hello World! >>> print "Hello World!" File "", line 1 print "Hello World!" ^ SyntaxError: Missing parentheses in call to 'print' <-- to "print" things to the screen, use print("message") How to have python print the following text: "double quotes?" >>> print(""double quotes?"") File "", line 1 print(""double quotes?"") ^ SyntaxError: invalid syntax >>> print("\"double quotes?\"") "double quotes?" <--- the \ symbol that appeared before a \" tells python that *that paricular "* is not the end of the pair of "'s that define the string in the print function 3. dealing with lists >>> >>> [1,2,3,4] [1, 2, 3, 4] >>> [1,2,3,4] + [1,2,3,4] [1, 2, 3, 4, 1, 2, 3, 4] ^ SyntaxError: invalid syntax >>> x=[1,2,3,4] >>> x [1, 2, 3, 4] >>> x+x [1, 2, 3, 4, 1, 2, 3, 4] >>> [y+1 for y in x] [2, 3, 4, 5] >>> [y+y for y in x] [2, 4, 6, 8] >>> [y*y for y in x] [1, 4, 9, 16] >>> 4. >>> fifty=list(range(0,50)) >>> squares=[x*x for x in fifty] >>> squares [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401] >>> The range function will let us make lists of integers, but what about decimals? Numpy gives us this >>> import numpy as np >>> x=np.arange(0,50,0.001) >>> x >>> x array([ 0.00000000e+00, 1.00000000e-03, 2.00000000e-03, ..., 4.99970000e+01, 4.99980000e+01, 4.99990000e+01]) >>> x.tolist() 5. plotting from matplotlib import pyplot as plt import numpy as np import matplotlib >>> x=[1,2,3,4,5,6,7,8,9,10] >>> y=[z*z for z in x] >>> plt.plot(x,y) [] >>> plt.show() >>> plt.scatter(x,y) 6. define a function def f(x): return x**(1/2) 7. list of basic operations: https://en.wikibooks.org/wiki/Python_Programming/Basic_Math#Mathematical_Operators math package documentation: https://docs.python.org/2/library/math.html matplotlib documentation: https://matplotlib.org/contents.html pyplot (in matplotlib) documentation: https://matplotlib.org/api/pyplot_api.html numpy documentation: https://docs.scipy.org/doc/numpy-1.13.0/ 8. one-dimensional random walk we may generate random numbers using the package random >>> import random >>> random.randint(0,5) 4 >>> random.randint(0,5) 4 >>> random.randint(0,5) 0 >>> random.randint(0,5) 4 >>> random.randint(0,5) 2 >>> random.randint(0,5) 1 >>> random.randint(0,5) 3 >>> for x in range(0,10): ... z.append(random.randint(0,1)) ... >>> z [0, 1, 0, 1, 0, 1, 1, 0, 0, 1] >>> for x in range(0,10): ... z.append(random.randint(0,1)) ... >>> z [0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1] >>> >>> z=[] >>> for x in range(0,10): ... z.append(random.randint(0,1)) ... >>> z [1, 1, 1, 0, 0, 0, 1, 0, 1, 0]