Python Tricks: The Book by Dan Bader

Python Tricks: The Book by Dan Bader

Author:Dan Bader
Language: eng
Format: mobi, epub, pdf
Published: 2018-04-23T17:54:01+00:00


As you can see, we can use the factory functions to create new Pizza objects that are configured just the way we want them. They all use the same __init__ constructor internally and simply provide a shortcut for remembering all of the various ingredients.

Another way to look at this use of class methods is to realize that they allow you to define alternative constructors for your classes.

Python only allows one __init__ method per class. Using class methods makes it possible to add as many alternative constructors as necessary. This can make the interface for your classes self-documenting (to a certain degree) and simplify their usage.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.