title: Iterator (iter()) function in Python.
body: <p>For dictionary, I can use <code>iter()</code> for iterating over keys of the dictionary.</p>
  
  <pre><code>y = {"x":10, "y":20}
  for val in iter(y):
      print val
  </code></pre>
  
  <p>When I have the iterator as follows,</p>
  
  <pre><code>class Counter:
      def __init__(self, low, high):
          self.current = low
          self.high = high
  
      def __iter__(self):
          return self
  
      def next(self):
          if self.current &gt; self.high:
              raise StopIteration
          else:
              self.current += 1
              return self.current - 1
  </code></pre>
  
  <p>Why can't I use it this way</p>
  
  <pre><code>x = Counter(3,8)
  for i in x:
      print x
  </code></pre>
  
  <p>nor</p>
  
  <pre><code>x = Counter(3,8)
  for i in iter(x):
      print x
  </code></pre>
  
  <p>but this way?</p>
  
  <pre><code>for c in Counter(3, 8):
      print c
  </code></pre>
  
  <p>What's the usage of <code>iter()</code> function?</p>
  
  <h3>ADDED</h3>
  
  <p>I guess this can be one of the ways of how <code>iter()</code> is used.</p>
  
  <pre><code>class Counter:
      def __init__(self, low, high):
          self.current = low
          self.high = high
  
      def __iter__(self):
          return self
  
      def next(self):
          if self.current &gt; self.high:
              raise StopIteration
          else:
              self.current += 1
              return self.current - 1
  
  class Hello:
      def __iter__(self):
          return Counter(10,20)
  
  x = iter(Hello())
  for i in x:
      print i
  </code></pre>