'''import math
class Point:
def reset(self) :
self.x=0;
self.y=0;
def Move(self,x,y) :
self.x=x;
self.y=y;
def Reset1(self):
self.move(0, 0);
def Calculate(self,other_point):
return math.sqrt(
(self.x-other_point.x)**2+(self.y-other_point.y)**2);
P1 = Point();
P2 = Point();
P1.reset();
P2.Move(5, 0);
print(P1.x, P1.y);
assert(P2.Calculate (P1)==P1.Calculate (P2));
P1.Move (9, 3);
print(P1.Calculate(P2));#self是P1然后参数
print(P1.Calculate(P1)); '''
class SecretString:
def __init__(self,plain_string,pass_phrase):
self.__plain_string = plain_string;
self.__pass_phrase = pass_phrase;
def decrypt(self,pass_phrase):
if pass_phrase==self.__pass_phrase:
return self.plain_string;
else:
return
secretString=SecretString("ACME: TOP Secret", "123456")
print(secretString.decrypt("antwep"))
#print(secretString.__plain_text)
print(secretString._SecretString__plain_string)
#名称改编 对于scretString 这个对象来说 我想访问内部的__plain_string 不能直接写成secretString.__plain_string
# 而是必须写成这样的secretString._SecretString__plain_string 也就是说是要 对象名.类名变量名 类名和变量名直接连接无分隔符
网友评论