如何创建自己的“提示"在IDLE中调用函数时? [英] How can I create my own "hint" when calling a function in IDLE?

查看:135
本文介绍了如何创建自己的“提示"在IDLE中调用函数时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我的问题可能令人困惑,很难问一些你不知道它到底是什么的东西(我将其称为'提示'),因此我对此表示歉意.话虽如此,这就是我的意思(白框中的文本):

I know my question might be confusing, it's hard to ask something you don't know what it is exactly (I'm going to call it 'hint'), so my apologies for that. Having that said, here it is what I mean (the text in the white box):

我的问题是:

  • 在调用函数时如何制作自己的提示文本(并对其进行自定义)?
  • 确切是什么?
  • 此示例中的文字是什么意思?

推荐答案

供以后参考:

  • 在调用函数时如何提出自己的提示[...]?

首先,我称之为"提示"有两种类型:

First, there are 2 types of 'hints' as I called them:

4.7.6.文档字符串:
以下是有关文档字符串的内容和格式的一些约定.

4.7.6. Documentation Strings:
Here are some conventions about the content and formatting of documentation strings.

第一行应始终是对象用途的简短摘要. [...] 此行应以大写字母开头,以句点结束.

The first line should always be a short, concise summary of the object’s purpose. [...] This line should begin with a capital letter and end with a period.

如果文档字符串中还有更多行,则第二行应为空白,以可视方式将摘要与描述的其余部分区分开.以下几行应为一个或多个描述对象的调用约定,其副作用等的段落. [...]

If there are more lines in the documentation string, the second line should be blank, visually separating the summary from the rest of the description. The following lines should be one or more paragraphs describing the object’s calling conventions, its side effects, etc. [...]

以下是多行文档字符串的示例:

Here is an example of a multi-line docstring:

>>> def my_function():
...     """Do nothing, but document it.
...
...     No, really, it doesn't do anything.
...     """
...     pass
...
>>> print(my_function.__doc__)
Do nothing, but document it.

    No, really, it doesn't do anything.

还有一个 Python 3.0引入的:

4.7.7.功能注释: 函数注释是有关所使用类型的完全可选的元数据信息通过用户定义的功能(有关更多信息,请参阅PEP 3107和PEP 484).

4.7.7. Function Annotations: Function annotations are completely optional metadata information about the types used by user-defined functions (see PEP 3107 and PEP 484 for more information).

注释作为字典存储在函数的 annotations 属性中,对函数的任何其他部分均没有影响.参数注释由参数名称后的冒号定义,后跟一个评估注释值的表达式.返回注释的定义是在参数列表和冒号(表示def语句的末尾)之间用文字->,然后是表达式.以下示例具有位置参数,关键字参数和带注释的返回值:

Annotations are stored in the annotations attribute of the function as a dictionary and have no effect on any other part of the function. Parameter annotations are defined by a colon after the parameter name, followed by an expression evaluating to the value of the annotation. Return annotations are defined by a literal ->, followed by an expression, between the parameter list and the colon denoting the end of the def statement. The following example has a positional argument, a keyword argument, and the return value annotated:

>>> def f(ham: str, eggs: str = 'eggs') -> str:
...     print("Annotations:", f.__annotations__)
...     print("Arguments:", ham, eggs)
...     return ham + ' and ' + eggs
...
>>> f('spam')
Annotations: {'ham': <class 'str'>, 'return': <class 'str'>, 'eggs': <class 'str'>}
Arguments: spam eggs
'spam and eggs'


查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆