31 August 2021

Python Boss Statements

So far, what can we do? We can write a list of Python statements and they will execute in seratum from top to bottom. Snore.

So far, every statement we have written has been an expression to be evaluated in the REPL or a simple command. Grammatically, we have spoken only in complete sentences.

But you know programming has these features.

A language missing one of these features is not a full-blown computer language. HTML breaks a page into elements, but it has no capability of selecting or iterating.

Every computer language has two types of statements.

Python Functions

def = "To define,"


def square(x):     x is a parameter basically local variable
    y = x*x        y is a local variable
    return y       This returns y and the frame pops
t = 6
#print(f"square{t} = {square(t)}")
print(square(t))
print(y)

What is a function in the math sense?

a function has an input and an output.
each input produces a definite output.

A function has three parts

D, a set that is the domain, or the allowable inputs for the function
R, a set that is the codomain, or the space of allowable outputs
f, a rule tying each element of the domain to some element in the codomain.

len is a mathematical function
    D = all sequences
    R = integers (nonnegative integers)
    f = return the number of items in the sequence according to its
    iterator.

Mathematical functions transoform a datum with no side effect.

The print function