Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rachanahegde authored Sep 29, 2021
1 parent fe3493b commit 86d9548
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
13 changes: 13 additions & 0 deletions day-54-intro-to-flask/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from flask import Flask

app = Flask(__name__)


@app.route('/')
def hello_world():
return 'Hello, World!'


if __name__ == "__main__":
app.run()

74 changes: 74 additions & 0 deletions day-54-intro-to-flask/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# ----------- Python Functions as First Class Objects: Passing & Nesting Functions -------------- #

# Functions can have inputs/functionality/output
def add(n1, n2):
return n1 + n2

def subtract(n1, n2):
return n1 - n2

def multiply(n1, n2):
return n1 * n2

def divide(n1, n2):
return n1 / n2

# Functions are first-class objects, can be passed around as arguments e.g. int/string/float etc.

def calculate(calc_function, n1, n2):
return calc_function(n1, n2)

result = calculate(add, 2, 3)
print(result)

# Functions can be nested in other functions

def outer_function():
print("I'm outer")

def nested_function():
print("I'm inner")

nested_function()

outer_function()

# Functions can be returned from other functions
def outer_function():
print("I'm outer")

def nested_function():
print("I'm inner")

return nested_function

inner_function = outer_function()
inner_function


# Simple Python Decorator Functions
import time

def delay_decorator(function):
def wrapper_function():
time.sleep(2)
#Do something before
function()
function()
#Do something after
return wrapper_function

@delay_decorator
def say_hello():
print("Hello")

# With the @ syntactic sugar
@delay_decorator
def say_bye():
print("Bye")

# Without the @ syntactic sugar
def say_greeting():
print("How are you?")
decorated_function = delay_decorator(say_greeting)
decorated_function()

0 comments on commit 86d9548

Please sign in to comment.