In this blog, I’ll combine pre learning 2 and 3.
Interviews with AI Leaders
Python actually has complex numbers as a primitive data type. There are two ways to make a complex number:
a = complex(1, 2)
ps: the textbook mentioned something interesting:
You’re probably used to using i for (-1)0.5. Just to confuse you, we’re going to use j instead. Why? Because to an electrical engineer, i stands for current, and there’s no arguing
What is Funtional Style? In the prelearning material, it is defined as:
In the functional programming style, one tries to use a very small set of primitives and means of combination. We’ll see that recursion is a very powerful primitive, which could allow us to dispense with all other looping constructs (while and for) and results in code with a certain beauty.
Another element of functional programming style is the idea of functions as first-class objects. That means that we can treat functions or procedures in much the same way we treat numbers or strings in our programs: we can pass them as arguments to other procedures and return them as the results from procedures. This will let us capture important common patterns of abstraction and will also be an important element of object-oriented programming.
A exmple of ancient algorithm:
It is an iterative algorithm: it starts with a guess about the square root, and repeatedly asks whether the guess is good enough. It’s good enough if, when we square the guess, we are close to the number, x, that we’re trying to take the square root of. If the guess isn’t good enough, we need to try to improve it. We do that by making a new guess, which is the average of the original
x / guess.
inline function in function. We called it closure in a more professional way.
- I once write a blog about this, see here
- we called it Variable Argument, *arg means positional arguments and **kwargs is keyword arguments. We’ve learn it the first day we use Python, but we have overlooked the most important symbol——*(star).
- the star symbol has two functions: pack and unpack, a sample:
def star_wrapper(a, b, *c):
When convey the arguments to a function, * allocate the paramters to the arguments in function in sequence. When the interpretor found a formal parameter with *, it will pack the unallocated actual parameter and convey it as a tuple to the formal parameter. Alike *, the double star(**) pack the keyword into a dictionary.