开始使用免费开始使用

编写文档字符串

我们刚刚学习了文档字符串的好处。在本练习中,您将练习编写可被 Sphinx 等文档生成器利用的文档字符串。

请注意,您提交的文档字符串必须与参考答案完全一致。如果多次提交仍然不对,建议重置为示例代码后重新开始。

本练习是课程的一部分

Python 中的软件工程原理

查看课程

练习说明

  • 补全文档字符串中记录参数的部分。
  • 补全文档字符串中对返回值的描述。
  • 补全文档字符串中的函数用法示例。

交互式实操练习

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

# Complete the function's docstring
def tokenize(text, regex=r'[a-zA-z]+'):
  """Split text into tokens using a regular expression

  :____ text: text to be tokenized
  :param ____: regular expression used to match tokens using re.findall 
  :____: a list of resulting tokens

  >>> ____('the rain in spain')
  ____
  """
  return re.findall(regex, text, flags=re.IGNORECASE)

# Print the docstring
help(tokenize)
编辑并运行代码