通过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.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
这里的sorted参数中的 / 不代表任何参数,它指示前面的都是位置参数,没有关键词参数,不过这种用法现在的Python本身并不支持,而是某些混合支持的Python版本中的用法。
在《Python中sorted(iterable, , key=None, reverse=False)函数参数定义中的独立星号()的含义》说明了这个函数中星号的用法,这二者的用法有点相似的味道,但还是有差别,并且星号的使用现在开发者可以在Python代码中自己使用,而斜杆却还不行。
老猿Python,跟老猿学Python! 博客地址:http://iyenn.com/index/link?url=https://blog.csdn.net/LaoYuanPython
文章知识点与官方知识档案匹配,可进一步学习相关知识
Python入门技能树首页概览333581 人正在系统学习中

老猿Python
微信公众号
专注Python相关语言、图像音视频处理、AI


评论记录:
回复评论: