function, parameters, keyword arguments

  • 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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值