Discuss / Python / 练习

练习

Topic source

东楚寒

#1 Created at ... [Delete] [Delete and Lock User]

L = ['Bart', 'Lisa', 'Adam'] n =len(L) while n>0: print('Hello,%s!'%L[-n]) n=n-1

请问print('hello,%s!'%L[-n])中的[-n]是什么来的啊!

东楚寒

#3 Created at ... [Delete] [Delete and Lock User]

[n]是list中的名字数量,每个名字可以用0,1,2或-3-2-1调用。这里考虑顺序用[-n],不考虑顺序还可以用[n-1]。

东楚寒

#4 Created at ... [Delete] [Delete and Lock User]

新手还在学习中[-n]方法是在评论中学到的。


  • 1

Reply