This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextlib | |
import sys | |
@contextlib.contextmanager | |
def logging_context_manager(): | |
print('logging_context_manager: enter') | |
try: | |
yield 'You are in a with-block!' | |
print('logging_context_manager: normal exit') | |
except Exception: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def greet(msg): | |
return msg.upper() | |
print greet('Welcome to Functional Programming') | |
message = greet | |
print message('Welcome to Functional Programming') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def greet(msg): | |
return msg.upper() | |
def speak(msg): | |
return msg.lower() | |
def display(func): | |
# storing the function in a variable | |
message = func('Welcome to Python Programming.') | |
print message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def addition(i): | |
def adds(j): | |
return i + j | |
return adds | |
result_add = addition(30) | |
print result_add(20) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from order import Order | |
from customer import Customer | |
def main(): | |
cust1 = Customer() | |
cust1.name = 'Rocky' | |
cust1.address = 'Florida' | |
cust1.enterprise = False | |
cust2 = Customer() | |
cust2.name = 'Jenifer' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderItem: | |
name = '' | |
itemnumber = '' | |
quantity = 0 | |
price = 0 | |
backorderd = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order: | |
# class attribute | |
orders = [] | |
# instance attributes | |
orderid = 0 | |
shipping_address = '' | |
expedited = False | |
shipped = False | |
customer = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Customer: | |
name = '' | |
address = '' | |
enterprise = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order: | |
# class attribute | |
orders = [] | |
# instance attributes | |
orderid = 0 | |
shipping_address = '' | |
expedited = False | |
shipped = False | |
customer = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order: | |
# class attribute | |
orders = [] | |
# instance attributes | |
orderid = 0 | |
shipping_address = '' | |
expedited = False | |
shipped = False | |
customer = None |