diff options
author | Kyle K <kylek389@gmail.com> | 2021-08-02 00:17:13 -0500 |
---|---|---|
committer | Kyle K <kylek389@gmail.com> | 2021-08-02 00:17:13 -0500 |
commit | 6505c9503c4925a2022a027a2414541a6cc20810 (patch) | |
tree | 4d14e18eee1c35dd9039b42d47721dcac660b80f /foo.py | |
parent | 5f20ddef75af630d64ee2987d2d8d24d484254aa (diff) | |
parent | 579ec7341483cf8701332e4652c27158cb808dcd (diff) | |
download | PythonPractice-6505c9503c4925a2022a027a2414541a6cc20810.tar.gz PythonPractice-6505c9503c4925a2022a027a2414541a6cc20810.tar.bz2 PythonPractice-6505c9503c4925a2022a027a2414541a6cc20810.zip |
Merge branch 'master' of cryptohash.nl:/home/git/PythonPractice
Diffstat (limited to 'foo.py')
-rw-r--r-- | foo.py | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -1,10 +1,21 @@ class Foo: pass + def hello(): print('hello, world') + x = 13 class Square(): + def __new__(cls, x): + instance = super(Square, cls).__new__(cls) + instance.__init__(x) + return instance.squared def __init__(self, x): self.inital = x - self.squared = x**2 + self.squared = x**2 # without .self the variable would be shared among all instances + def __str__(self): + return str(self.__class__) + ": " + str(self.__dict__) + +area = Square(5.5) # if __new__ wasn't implemented, instead of 30.25 float print would call __str__ and return <class '__main__.Square'>: {'inital': 5.5, 'squared': 30.25} +print(area)
\ No newline at end of file |