wei/unit_3/cars.py

21 lines
394 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

cars= ['bmw', 'audi', 'toyota', 'subaru']
#sort可永久对列表排序按照字母顺序
cars.sort()
print(cars)
cars= ['bmw', 'audi', 'toyota', 'subaru']
#surted可临时对列表进行排序
print(sorted(cars))
print(cars)
#reverse可反向打印列表再次使用即可恢复列表
cars.reverse()
print(cars)
cars.reverse()
print(cars)
#len可确定列表长度
print(len(cars))