Created
February 10, 2019 07:54
-
-
Save Robofied/2d4685743085252474c4f3208d226e13 to your computer and use it in GitHub Desktop.
Intermediate Python
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 office_hours(start_time, finish_time): | |
s = start_time | |
f = finish_time | |
def cal_working_hours(): | |
return ('Hi '+ '! Your office hours will be ' + str((int(f.split(':')[0]) - int(s.split(':')[0])))+ | |
' hours.') | |
## returning the function but without () | |
return cal_working_hours | |
## Here it will return only function name because () or execution of function didn't happen. | |
cal_hours = office_hours('10:00','18:00') | |
cal_hours | |
#[Output]: | |
#<function __main__.office_hours.<locals>.cal_working_hours()> | |
## How to check the name of the funtion | |
print(cal_hours.__name__) | |
#[Output]: | |
#'cal_working_hours' | |
""" Now on that variable using "()" will be able to execute the function | |
See here this cal_working_hours defined inside the office_hours function, and using the variables passed | |
into the office hours still this cal_working_hours able to execute beacuse of closures """ | |
print(cal_hours()) | |
#[Output]: | |
#'Hi ! Your office hours will be 8 hours.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment