| cars = ['bmw', 'audi', 'toyota', 'subaru'] print sorted(cars ) print sorted(cars , reverse=True) |
输出:
['audi', 'bmw', 'subaru', 'toyota']
['toyota', 'subaru', 'bmw', 'audi']
cars = ['bmw', 'audi', 'toyota', 'subaru']
cars.sort()
print(cars)
cars = ['bmw', 'audi', 'toyota', 'subaru']
cars.sort(reverse=True)
print(cars)
cars = ['bmw', 'audi', 'toyota', 'subaru']
print("Here is the original list:")
print(cars)
print("nHere is the sorted list:")
print(sorted(cars))
print('nHere is the original list again:')
print(cars)
print("nHere is the reverse sorted list:")
print(sorted(cars, reverse=True))
cars = ['bmw', 'audi', 'toyota', 'subaru']
print(cars)


