primes get_primes(next(primes)next(primes)next(primes( for _prime in zip(range( )primes)print(primeend=" every time you create new object with get_primes(the iterator is the same infinite lazy sequence--another example might pass in some initializing values that affected the result--but the object itself is stateful as it is consumed incrementally multiple dispatch very interesting approach to programming multiple paths of execution is technique called "multiple dispatchor sometimes "multimethods the idea here is to declare multiple signatures for single function and call the actual computation that matches the types or properties of the calling arguments this technique often allows one to avoid or reduce the use of explicitly conditional branchingand instead substitute the use of more intuitive pattern descriptions of arguments long time agothis author wrote module called multimethods that was quite flexible in its options for resolving "dispatch linearizationbut is also so old as only to work with python xand was even written before python had decorators for more elegant expression of the concept matthew rocklin' more recent multipledis patch is modern approach for recent python versionsalbeit it lacks some of the theoretical arcana explored in my ancient module ideallyin this author' opiniona future python version would include standardized syntax or api for multiple dispatch (but more likely the task will always be the domain of third-party librariesto explain how multiple dispatch can make more readable and less bug-prone codelet us implement the game of rock/paper/scissors in three styles let us create the classes to play the game for all the versionsclass thing(object)pass class rock(thing)pass multiple dispatch