Class, Iterator, etc.

Object oriented programming.

We do not want you to create classes. Just understand them so that you can
use them from the available libraries.

Code -


class complex_number:

init


z=complex_number(2,5)

print z.re, z.im


class complex_number:

init



self.re + self.im

z=complex_number(2,5)

print z.re, z.im, z.absquare()

Example - integer_list, dna_seq

Purpose of class is to make sure data conforms to standard.

Iterables, Iterators, Generators

Very powerful concepts.

Collection.

Map, lambda.

http://nvie.com/posts/iterators-vs-generators/

All codes here.


a=iter(range(5))
print a.next()
print a.next()
print a.next()
print a.next()
print a.next()

http://nvie.com/posts/iterators-vs-generators/


>>> from itertools import cycle
>>> colors = cycle(['red', 'white', 'blue'])
>>> next(colors) ‘red’
>>> next(colors) ‘white’
>>> next(colors) ‘blue’
>>> next(colors) ‘red’

Protocols -

http://anandology.com/python-practice-book/iterators.html

http://www.dabeaz.com/generators-uk/

https://stackoverflow.com/questions/9884132/what-exactly-are-pythons-iterator-iterable-and-iteration-protocols

https://stackoverflow.com/questions/32799980/what-exactly-does-iterable-mean-in-python

** make sure example is changed **

https://docs.python.org/2/tutorial/classes.html

http://www.diveintopython3.net/iterators.html

http://nvie.com/posts/iterators-vs-generators/

The following code is from online.


class Fib:
    ‘'’iterator that yields numbers in the Fibonacci sequence’’’

init

iter



next





x=Fib(10)
print x