Python中sorted(iterable, /, *, key=None, reverse=False)的参数中的斜杆是什么意思?

通过help(sorted)查看sorted的帮助文档,显示如下:

Help on built-in function sorted in module builtins:

sorted(iterable, /, *, key=None, reverse=False)
    Return a new list containing all items from the iterable in ascending order.
    
    A custom key function can be supplied to customize the sort order, and the
    reverse flag can be set to request the result in descending order.

这里的sorted参数中的 / 不代表任何参数,它指示前面的都是位置参数,没有关键词参数,不过这种用法现在的Python本身并不支持,而是某些混合支持的Python版本中的用法。
《Python中sorted(iterable, , key=None, reverse=False)函数参数定义中的独立星号()的含义》说明了这个函数中星号的用法,这二者的用法有点相似的味道,但还是有差别,并且星号的使用现在开发者可以在Python代码中自己使用,而斜杆却还不行。

老猿Python,跟老猿学Python! 博客地址:https://blog.csdn.net/LaoYuanPython

原文地址:https://www.cnblogs.com/LaoYuanPython/p/11144507.html