Skip to content

Commit 52df16d

Browse files
committed
在类的外面定义方法,类的内部调用
1 parent 7ed26b6 commit 52df16d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

def_scope.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def bar(self, y):
2+
return self.x + y
3+
4+
5+
class Foo(object):
6+
def __init__(self, x):
7+
self.x = x
8+
9+
bar = bar;
10+
11+
12+
foo = Foo(333);
13+
print(foo.bar(3))
14+
15+
#result:336

0 commit comments

Comments
 (0)