Created
February 10, 2019 07:58
-
-
Save Robofied/0632fabf92493f24b7c685b5a0f87d0c 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
## Creating a function which can take multiple(any no. of ) arguments | |
## Here in this example it is not much necessary to give unknown number of parameters | |
## But in some cases we are not knowing then this *args is very useful | |
def office_hours(*args): | |
return ('Hi!'+ str(args[0]) +' Your office hours will be ' + str((int(args[2].split(':')[0]) - int(args[1].split(':')[0])))+ | |
' hours.') | |
## calling the above function | |
office_hours('Rajesh','10:00','18:00') | |
#[Output]: | |
#'Hi!Rajesh Your office hours will be 8 hours.' | |
## You can pass any no. of arguments though last parameter we are not using in our function | |
office_hours('Rajesh','10:00','18:00','hello') | |
#[Output]: | |
#'Hi!Rajesh 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