Discuss / Python / python路上的毛毛虫

python路上的毛毛虫

Topic source

class Fib(object): def getitem(self, n): a, b = 1, 1 for x in range(n): a, b = b, a + b return a

请问这里的n是可以不传入值的嘛?如果不传入的话意味着是无限的嘛?不会再for循环里出不来吗?

这里的n值是取决于你外部的索引值 传入Fib()[n] 不传入[]不会调用getitem 不在[]中传入n值肯定会报错的 跟普通的 list 这些没区别

s=[1,2,3,4] s [1, 2, 3, 4] s[0] 1 s[] SyntaxError: invalid syntax


  • 1

Reply