Base Python

Basics

For Loops

for x in []:
	~stuff~
total = 0
for value, weight in zip([2,3,19],[0.2,0.3,0.5]):
    total += weight * value
print('Weighted average is: {0}'.format(total))

The function dir() provides a list of objects in a namespace. When used with an object, it includes attributes and any methods associated with the object.

Defining Functions

there is already a function for plotting lines, this is just reference for defining functions

def abline(ax, b, m, *args, **kwargs):
    "Add a line with slope m and intercept b to ax"
    xlim = ax.get_xlim()
    ylim = [m * xlim[0] + b, m * xlim[1] + b]
    ax.plot(xlim, ylim, *args, **kwargs)

Connect With Me!