Python:帮助(范围)输出中的斜杠是什么意思? [英] Python: What does the slash mean in the output of help(range)?

查看:385
本文介绍了Python:帮助(范围)输出中的斜杠是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

/ 在Python 3.4的帮助中为范围在括号之前?

What does the / mean in Python 3.4's help output for range before the closing parenthesis?

>>> help(range)
Help on class range in module builtins:

class range(object)
 |  range(stop) -> range object
 |  range(start, stop[, step]) -> range object
 |  
 |  Return a virtual sequence of numbers from start to stop by step.
 |  
 |  Methods defined here:
 |  
 |  __contains__(self, key, /)
 |      Return key in self.
 |  
 |  __eq__(self, value, /)
 |      Return self==value.

                                        ...


推荐答案

它表示 仅限位置的结束参数,您不能的参数用作关键字参数。这些参数只能在C API中指定。

It signifies the end of the positional only parameters, parameters you cannot use as keyword parameters. Such parameters can only be specified in the C API.

这意味着参数 __包含__ 只能通过位置( range(5).__包含__(3))传递,而不是作为关键字参数( range(5).__包含__(key = 3)),你可以使用纯python函数中的位置参数来实现

It means the key argument to __contains__ can only be passed in by position (range(5).__contains__(3)), not as a keyword argument (range(5).__contains__(key=3)), something you can do with positional arguments in pure-python functions.

另请参阅参数诊所文档:


要在Argument Clinic中将所有参数标记为仅位置,请在行后添加一个 / 最后一个参数缩进与参数行相同。

To mark all parameters as positional-only in Argument Clinic, add a / on a line by itself after the last parameter, indented the same as the parameter lines.

语法也被定义为可能将来包含在Python中,请参阅 PEP 457 - 仅限Position-only参数的语法 。目前,PEP作为语法的保留,实际上没有实际的计划。

The syntax has also been defined for possible future inclusion in Python, see PEP 457 - Syntax For Positional-Only Parameters. At the moment the PEP acts as a reservation on the syntax, there are no actual plans to implement it as such.

这篇关于Python:帮助(范围)输出中的斜杠是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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