- container for a few lines of codes that perform a specific task
- parameters are used to pass information to funtion
def greet_user(name):
print(f'Hi {name}!')
print('Start')
greet_user('John')
-
when a function has a parameter, we are obligated to pass a value to that parameter
-
parameters are the holes or place holders that we define in a function to receive information. Arguments are the actual pieces of information that we supply to this function.
-
positional argument: their position or order are important; keyword argument: their order doesn’t matter.
-
keyword argument can improve readability.
-
keyword arguments should always come after the position arguments
def greet_user(first_name, last_name):
print(f'Hi {first_name} {last_name}!')
print('Start')
greet_user(last_name = 'Moira', first_name = 'Chen')
- return statement: return values to the callers
- by default, all the functions return None( None is an object that represent the absence of a value
- function should not worry about input and printing
def emojis_converter(message):
words = message.split(" ")
emojis = {
":)": "🙂",
":(": "😟"
}
output = ''
for word in words:
output += emojis.get(word, word) + ' '
return output
message = input("> ")
result = emojis_converter(message)
print(result)