Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

return function in python

# Here we define the function with a parameter
# At the return statement, function ends execution
# And return the value or result of the code block
def greet(lang):
    if lang == 'spanish':
        return('Hola!')
    elif lang == 'french':
        return('Bonjour!')
    else:
        return('Hello!')

# Now we can call the function and print the returning value
print(greet('spanish'), 'Lucia.') # Output - Hola! Lucia.
print(greet('french'), 'Emma.') # Output - Bonjour! Emma.
print(greet('english'), 'James.')# Output - Hello! James.
Source by www.py4e.com #
 
PREVIOUS NEXT
Tagged: #return #function #python
ADD COMMENT
Topic
Name
9+7 =