ID photo of Ciro Santilli taken in 2013 right eyeCiro Santilli OurBigBook logoOurBigBook.com  Sponsor 中国独裁统治 China Dictatorship 新疆改造中心、六四事件、法轮功、郝海东、709大抓捕、2015巴拿马文件 邓家贵、低端人口、西藏骚乱
python/getitem.py
#!/usr/bin/env python3
class C:
    def __init__(self, x0, x1):
        self.x0 = x0
        self.x1 = x1

    def __getitem__(self, i):
        if i == 0:
            return self.x0
        elif i == 1:
            return self.x1
        else:
            raise IndexError(i)
c = C(1, 2)
assert c[0] == 1
assert c[1] == 2
x0, x1 = c
assert x0 == 1
assert x1 == 2

Ancestors (13)

  1. Python __getitem__
  2. Python special method
  3. Python classes
  4. Python language feature
  5. Python
  6. List of programming languages
  7. Programming language
  8. Software
  9. Computer
  10. Information technology
  11. Area of technology
  12. Technology
  13. Ciro Santilli's Homepage