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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容