# -*- coding: utf-8 -*- """ Created on Sat Sep 19 15:39:27 2020# @author: Jake Bobowski """ # Created using Spyder(Python 3.7) # Preliminaries # Lines in a Python script (*.py file) that begin using the number sign are # comments. It is good practice to thoroughly comment your scripts. # The small initial investment in time to comment your work will same you # large amounts of time in the long run. ''' It is also possible to add multiline comments using the triple quotes notation. Technically, this is a string and not a comment, but it can effectively be used for long, multiline comments. ''' ''' A useful command to run in the IPython console before running a new script is '%reset'. This command will clear all previous variable assignments. ''' # Addition, subtraction, multiplication, and division # If you run a script with a 3+5 statement, it will execute but no output will # appear in the console. 3 + 5 # If you want to see the result, use the 'print()' statement. print(3 + 5) # Alternatively, you can assign the result of the operation to a variable and # then print that variable. x = 3 + 5 print(x) # The synatax for the other common operations are as you'd expect: y = (3 + 5*2)/4 print(y) # You could format your outputs too: print('y =', y) # To do powers, use the ** notation. print (3**2) # Note that '^' is not used to evaluate powers in Python. It is the XOR # (exclusive OR) logic operator. # Python will accept scientific notation as follows: hbar = 1.05e-34 kB = 1.38e-23 print('hbar =', hbar, '& kB =', kB) # Some of the other common mathematical functions, like trig functions, # exponentials, and logs require the math module. For example, cos(1) won't # work without the math module. To load the math module, use: import math # WE can now evaluate the cosine function using x = math.cos(1) print(x) # Pi and e are also available in the math module. print('pi =', math.pi, '& e =', math.e) # Here's an inverse trig function print(math.atan(9999)/math.pi) # Here are the exponential and logarithmic functions print(math.exp(-1)) print(math.log(math.exp(-1))) # natural log, i.e. ln print(math.log10(10**-2)) # log (base 10) # There are two ways to calculate square roots print(53**0.5) print(math.sqrt(53))