20201224-1

1-1
# bicycles.py bicycles = ['trek', 'cannondale', 'redline', 'specialized'] message = "My first bicycle was a " + bicycles[0].title() + "." print(message)
--->
My first bicycle was a Trek.
1-2
# cars.py

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 reverse alphabetical list:")
print(sorted(cars, reverse=True))

print("\nHere is the original list again:")
print(cars)
1-3
# motorcycles
motorcycles = ['honda', 'yamaha', 'suzuki', 'ducati'] 
print(motorcycles)

too_expensive = 'ducati'
motorcycles.remove(too_expensive)
print(motorcycles)
print("\nA " + too_expensive.title() + " is too expensive for me.")

注:知识点链接 

https://www.cnblogs.com/azxsdcv/p/14183819.html

https://www.cnblogs.com/azxsdcv/p/14183874.html

上一篇:第三章 列表简介


下一篇:Python学习之路(三)