注册 登录
编程论坛 Python论坛

新人请教问题,请各位大神不要笑话~~

aa2820981 发布于 2019-07-17 09:29, 2145 次点击
用sorted()函数为例,变量名加深为apple,
那么sorted(apple)和apple.sorted()是不是一样的功能?

另外,当想sorted传递参数数reverse=True时,如果我用sorted(apple)这种方法,那么我这个参数应该放在上面地方?

谢谢!
6 回复
#2
TysonKoothra2019-07-17 14:00
一般我都按下面的方式用。
程序代码:

>>> apple = [9, 8, 5, 1, 6]
>>> sorted(apple)
[1, 5, 6, 8, 9]
>>> apple = [9, 8, 5, 1, 6]
>>> apple.sort()
>>> apple
[1, 5, 6, 8, 9]
>>> apple.sort(reverse=True)
>>> apple
[9, 8, 6, 5, 1]
#3
songpengyong2019-07-17 21:44
回复 2楼 TysonKoothra
这就是排序,肯定写上面,不然怎么找得到
#4
aa28209812019-07-18 09:22
回复 2楼 TysonKoothra
谢谢
#5
aa28209812019-07-18 09:22
回复 3楼 songpengyong
懂啦,谢谢
#6
lwy2xxj2019-07-19 10:25
#7
程序员20192019-07-19 23:33
1