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> 

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据