My QA Projects

QA Projects I was involded.

View on GitHub

Functions are First-Class Citizens

def answer():
    print(42)

def run_something(func):
    func()

run_something(answer)
# pass answer to run_something => using function as data
type(run_something)
<class 'function'>
def add_args(arg1, arg2):
    print(arg1 + arg2)

def run_something_with_args(func, arg1, arg2):
    func(arg1, arg2)

    # func - function to run
    # arg1 - first argument for func
    # arg2 - 2nd argument for func

Inner Functions

def outer (a,b):
    def inner(c,d):
        return c+d
    return inner(a,b)

outer(4,7)
# Output
11
def knights (saying):
    def inner(quote):
        return "We are the knights who say: '%s'" %quote
    return inner(saying)

knights ('Ni!')
# Output
We are the knights who say: Ni!

Closure

def knights2(saying):
        def inner2():
        return "We are the knights who say: '%s'" %quote
    return inner2

knights ('Ni!')
# Output
We are the knights who say: Ni!

=> to do more research on this!