Jump to content

Python: Difference between revisions

434 bytes added ,  28 July 2020
Line 298: Line 298:
b = islice(a, 3)
b = islice(a, 3)
list(b) # [0,1,2]
list(b) # [0,1,2]
</syntaxhighlight>
==classes==
===Static and Class methods===
See [https://realpython.com/instance-class-and-static-methods-demystified/ realpython]
<syntaxhighlight lang="python">
class MyClass:
    def method(self):
        return 'instance method called', self
    @classmethod
    def classmethod(cls):
        return 'class method called', cls
    @staticmethod
    def staticmethod():
        return 'static method called'
</syntaxhighlight>
</syntaxhighlight>