Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
amamov committed Jun 1, 2021
1 parent 47fd205 commit 242dfd3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 61 deletions.
4 changes: 0 additions & 4 deletions Ch-03/02-encapsulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ def cal_add(self, a, b):
def how_many(cls):
return f"We have {cls.population} robots."

@staticmethod
def are_you_robot():
print("yes!!")


droid1 = Robot("R2-D2")
droid1.say_hi()
Expand Down
10 changes: 3 additions & 7 deletions Ch-03/03-encapsulation-review.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,20 @@ def cal_add(self, a, b):
def how_many(cls):
return f"We have {cls.population} robots."

@staticmethod
def are_you_robot():
print("yes!!")


droid1 = Robot("R2-D2")
droid1.say_hi()

Robot.how_many()
print(Robot.how_many())

droid2 = Robot("amamov")
droid2.say_hi()
Robot.how_many()
print(Robot.how_many())

print("\nRobots can do some work here.\n")
print("Robots have finished their work. So let's destroy them.")
droid1.die()
Robot.how_many()
print(Robot.how_many())
droid2.die()

# //* dir() : 모든 속성 값을 알 수 있다.
Expand Down
30 changes: 30 additions & 0 deletions Ch-03/04-self.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# [self의 이해]
# ** self는 인스턴스 객체이다!!
# ** 클래스 안에 있는 self의 주소와 만들어진 인스턴스의 주소는 같다! 즉, self는 인스턴스 그 자체이다!


class SelfTest:

# * 클래스 변수
name = "amamov"

def __init__(self, x):
self.x = x # * 인스턴스 변수

# * 클래스 메서드
@classmethod
def function1(cls):
print(f"cls : {cls}")
print("function 1 called !")

# *인스턴스 메서드
def function2(self):
print(f"self : {self}")
print("class안의 self의 주소:", id(self))
print("function 2 called !")


test_instance = SelfTest(17)


print("인스턴스의 주소:", id(test_instance))
File renamed without changes.
50 changes: 0 additions & 50 deletions Ch-03/05-self.py

This file was deleted.

30 changes: 30 additions & 0 deletions Ch-03/study.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# [self의 이해]
# ** self는 인스턴스 객체이다!!
# ** 클래스 안에 있는 self의 주소와 만들어진 인스턴스의 주소는 같다! 즉, self는 인스턴스 그 자체이다!


class SelfTest:

# * 클래스 변수
name = "amamov"

def __init__(self, x):
self.x = x # * 인스턴스 변수

# * 클래스 메서드
@classmethod
def function1(cls):
print(f"cls : {cls}")
print("function 1 called !")

# *인스턴스 메서드
def function2(self):
print(f"self : {self}")
print("class안의 self의 주소:", id(self))
print("function 2 called !")


test_instance = SelfTest(17)


print("인스턴스의 주소:", id(test_instance))

0 comments on commit 242dfd3

Please sign in to comment.