Skip to main content
 首页 » 编程设计

python之对 python 数组进行排序

2025年05月04日1098°冷暖

opt=[] 
opt=["opt3","opt2","opt7","opt6","opt1"] 
for i in range(len(opt)): 
     print opt[i] 

上面的输出是

opt3,opt2,opt7,opt6,opt1 

如何对上面的数组进行升序排序..

请您参考如下方法:

使用.sort()如果你想对原始列表进行排序。 (opt.sort())

使用sorted()如果你想要它的排序副本。