Python Forum
what does x reprsent in this code ?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what does x reprsent in this code ?
#24
another quiz,
in the following code:

class MyNumbers:
  def __iter__(self):
    self.a = 1
    return self

  def __next__(self):
    if self.a <= 20:
      x = self.a
      self.a += 1
      return x
    else:
      raise StopIteration

myclass = MyNumbers()
myiter = iter(myclass)

for x in myiter:
  print(x)
i see that in line 14 - myclass = Mynumbers() - as i understand it - myclass is a new variable ? which is assigned the value of the class MyNumbers ?
but then how is it that the class is being wrote with () - (that's a function feature, isn't it ?)
Reply


Messages In This Thread
RE: what does x reprsent in this code ? - by buran - Apr-09-2020, 02:25 PM
RE: what does x reprsent in this code ? - by buran - Apr-10-2020, 07:20 PM
RE: what does x reprsent in this code ? - by buran - Apr-19-2020, 01:49 PM
RE: what does x reprsent in this code ? - by astral_travel - Apr-27-2020, 07:29 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020