L = ['Bart', 'Lisa', 'Adam'] n =len(L) while n>0: print('Hello,%s!'%L[-n]) n=n-1
请问print('hello,%s!'%L[-n])中的[-n]是什么来的啊!
[n]是list中的名字数量,每个名字可以用0,1,2或-3-2-1调用。这里考虑顺序用[-n],不考虑顺序还可以用[n-1]。
新手还在学习中[-n]方法是在评论中学到的。
Sign in to make a reply
东楚寒
L = ['Bart', 'Lisa', 'Adam'] n =len(L) while n>0: print('Hello,%s!'%L[-n]) n=n-1