10 月 102020
#for循环和if条件判断
#定义列表并赋值给变量
songlist = ['Holy Diver', 'Thunderstruck', 'Rebel Rebel']
#循环从列表中取值赋值给变量
for song in songlist:
if song == 'Holy Diver': #条件判断,比较当前song的取值
print(song, ' - Dio') #打印歌曲名称和歌手名称
elif song == 'Thunderstruck':
print(song, ' - AC/DC')
elif song == 'Rebel Rebel':
print(song, ' - David Bowie')
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python39/python.exe c:/Users/harveymei/hello.py
Holy Diver - Dio
Thunderstruck - AC/DC
Rebel Rebel - David Bowie
PS C:\Users\harveymei>