开始使用免费开始使用

含多个参数的函数

Hugo 在上一节课讲解了在定义函数时使用多个参数。现在请根据所学进一步修改 shout() 函数。在这里,您将把 shout() 改为接收两个参数。您之前编写的 shout() 函数的部分代码已给出。

本练习是课程的一部分

Python 函数入门

查看课程

练习说明

  • 修改函数头,使其按顺序接收两个参数 word1word2
  • word1word2 各自与 '!!!' 连接,并分别赋给 shout1shout2
  • 按顺序将 shout1shout2 连接在一起,赋给 new_shout
  • 调用 shout() 时按顺序传入字符串 'congratulations''you'。将返回值赋给 yell

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Define shout with parameters word1 and word2
def shout(____, ____):
    """Concatenate strings with three exclamation marks"""
    # Concatenate word1 with '!!!': shout1
    
    
    # Concatenate word2 with '!!!': shout2
    
    
    # Concatenate shout1 with shout2: new_shout
    

    # Return new_shout
    return new_shout

# Pass 'congratulations' and 'you' to shout(): yell


# Print yell
print(yell)
编辑并运行代码