mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-17 01:51:39 +09:00
51 lines
667 B
Python
51 lines
667 B
Python
class Foo:
|
|
def __init__(self, x):
|
|
assert x == 5
|
|
self.x = x
|
|
|
|
def square(self):
|
|
return self.x * self.x
|
|
|
|
y = 7
|
|
|
|
foo = Foo(5)
|
|
|
|
assert foo.y == Foo.y
|
|
assert foo.x == 5
|
|
assert foo.square() == 25
|
|
|
|
class Fubar:
|
|
def __init__(self):
|
|
self.x = 100
|
|
|
|
@property
|
|
def foo(self):
|
|
value = self.x
|
|
self.x += 1
|
|
return value
|
|
|
|
|
|
f = Fubar()
|
|
assert f.foo == 100
|
|
assert f.foo == 101
|
|
|
|
|
|
class Bar:
|
|
@classmethod
|
|
def fubar(cls, x):
|
|
assert cls is Bar
|
|
assert x == 2
|
|
|
|
@staticmethod
|
|
def kungfu(x):
|
|
assert x == 3
|
|
|
|
|
|
bar = Bar()
|
|
|
|
bar.fubar(2)
|
|
Bar.fubar(2)
|
|
|
|
bar.kungfu(3)
|
|
Bar.kungfu(3)
|