17
loading...
This website collects cookies to deliver better user experience
def
worddef
will be followed by the name of the function, recommended in all lower case():
, denoting the end of defining a functionwake_up
when you run the file, however, you would need to call it to make sure it does what you have asked it to do. You can call it by writing the unique name of the function you have defined, followed by the parenthesis.wake_up
has two parameters time
& meridian
. You can see that time
requires a value however meridian
has a pre-assigned value of a string 'AM'
, which means that the meridian is optional for you to assign. Here's how you can call this function:wake_up(12)
--> This will print I woke up at 12 AM
wake_up(time=12)
--> This will also print I woke up at 12 AM
wake_up(12, 'PM')
--> This will print I woke up at 12 PM
wake_up(meridian='PM', time=12)
--> This will print I woke up at 12 PM
wake_up('PM', 12)
would print --> I woke up at PM 12return
is added at the end which allocates the output to a variable outside the function which can then be re-used.return
would be ignored by the console as the function would immediately end and allocate the value.returned_value = add(2, 3)
--> This doesn't print any value but instead allocated the variable returned_value
with 5
.returned_value = add(number1 = 6, number2 = 3)
--> This too doesn't print any value but instead allocated the variable returned_value
with 9
.TypeError
SyntaxError
return
command on the same indentation level would be ignored.sum
return
statementnum
to the global variable addition