Quick actions

cmd+k|ctrl+k

Navigation

Languages

Python Web-L07(high level func)

Snippet info

Language

Python

Visibility

public

Author

victormakwaitat

Created

2025-02-12T04:04:07.244397Z

Updated

2025-02-12T08:53:01.920135Z

#case 1
"""def a():
    print("I am from function a")
    return b
def b():
    print("I am from function b")
    return a
a()()()()()()()()"""

#case 2
"""def a(x):
    print("I am from function a")
    return x()
def b():
    print("I am from function b")
    return a
a(b)(b)"""

#case 3
"""def a():
    print("I am from function a")
    return b
def b():
    print("I am from function b")
    return c
def c():
    print("I am from function c")
    return a
b()()()"""

#case 4
"""def a():
    print("I am from function a")
    return b
def b():
    print("I am from function b")
    return c
def c():
    print("I am from function c")
    return a,b
#x(),y() = c() <- cannot do this as left hand side is address only not expression
x,y =c()
x()
y()"""

#case 5
"""def c():
    print("I am from function c")
    return lambda : print("I am from lambda function")
c()()"""

#case 6
"""def a():
    print("I am from function a")
    return c
def c():
    print("I am from function c")
    return lambda : a()
c()()
a()()"""

#case 7
"""def age(x):
    print("I am {0} years old !".format(x))
#dict = {"name" : lambda : print("I am from dict"), "age" : age}
dict = {"name" : lambda : print("I am from dict"), "age" : lambda x : age(x)}
dict["name"]()
dict["age"](35)"""

#case 8 <- insert default value
"""default = 30
def age(x=default):
    print("I am {0} years old !".format(x))
#dict = {"name" : lambda : print("I am from dict"), "age" : age}
# dict. lambda:age(x) <- lambda function is to delay function and don't run it immediately in line 76
dict = {"name" : lambda : print("I am from dict"), "age" : lambda : age(default)}
#dict = {"name" : lambda : print("I am from dict"), "age" : lambda login : age() if login else print("login in fail")}
dict["name"]()
dict["age"]()
#dict["age"](False)"""

#case 9 <- insert default value
"""default = 30
def age(x=default):
    print("I am {0} years old !".format(x))
#dict = {"name" : lambda : print("I am from dict"), "age" : age}
# dict. lambda:login:age() <- lambda function is to delay function and don't run it immediately in line 89
#dict = {"name" : lambda : print("I am from dict"), "age" : lambda : age(default)}
dict = {"name" : lambda : print("I am from dict"), "age" : lambda login : age() if login else print("login in fail")}
dict["name"]()
#dict["age"]()
dict["age"](True)
dict["age"](False)"""

#case 10 pass list into function
"""def a(item):
    print("I am from function a", item)
def b(m):
    for i in m:
        a(i)
l = [1,2,3]
b(l)"""

#case 11 nested function
"""def a():
    def b():
        print("I am from function b")
    return b
x = a()
x()"""

#case 12 nested function
"""def a():
    x = 1
    def b():
        print("I am from function b", x)
    return b
x = a()
x()"""

#case 13 nested function <- increase privacy
def a(tax_per):
    def b(amount):
        print("sale tax", tax_per *amount)
    return b
x = a(0.05)
x(100)
x(50)

#case 14 buildin function callable-> don't let program crush
#a = 1
print(callable(a))
a(0.05) if callable(a) else print("can't run function a")
a = 1
a() if callable(a) else print("can't run function a")
INFO