diff --git a/Code/Python9Code/.idea/Python9Code.iml b/Code/Python9Code/.idea/Python9Code.iml new file mode 100644 index 0000000..6711606 --- /dev/null +++ b/Code/Python9Code/.idea/Python9Code.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Code/Python9Code/.idea/inspectionProfiles/profiles_settings.xml b/Code/Python9Code/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..c23ecac --- /dev/null +++ b/Code/Python9Code/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/Code/Python9Code/.idea/misc.xml b/Code/Python9Code/.idea/misc.xml new file mode 100644 index 0000000..dac3415 --- /dev/null +++ b/Code/Python9Code/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Code/Python9Code/.idea/modules.xml b/Code/Python9Code/.idea/modules.xml new file mode 100644 index 0000000..0a15fc1 --- /dev/null +++ b/Code/Python9Code/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Code/Python9Code/.idea/workspace.xml b/Code/Python9Code/.idea/workspace.xml new file mode 100644 index 0000000..5177d29 --- /dev/null +++ b/Code/Python9Code/.idea/workspace.xml @@ -0,0 +1,680 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1500999902927 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Code/Python9Code/com/__init__.py b/Code/Python9Code/com/__init__.py new file mode 100644 index 0000000..24ba15a --- /dev/null +++ b/Code/Python9Code/com/__init__.py @@ -0,0 +1,2 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- \ No newline at end of file diff --git a/Code/Python9Code/com/twowater/__init__.py b/Code/Python9Code/com/twowater/__init__.py new file mode 100644 index 0000000..24ba15a --- /dev/null +++ b/Code/Python9Code/com/twowater/__init__.py @@ -0,0 +1,2 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- \ No newline at end of file diff --git a/Code/Python9Code/com/twowater/mtest0.py b/Code/Python9Code/com/twowater/mtest0.py new file mode 100644 index 0000000..6d91e42 --- /dev/null +++ b/Code/Python9Code/com/twowater/mtest0.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +# -*- coding: UTF-8 -*- + +class Test: + def prt(self): + print(self) + print(self.__class__) + +t = Test() +t.prt() \ No newline at end of file diff --git a/Code/Python9Code/com/twowater/mtest1.py b/Code/Python9Code/com/twowater/mtest1.py new file mode 100644 index 0000000..2330058 --- /dev/null +++ b/Code/Python9Code/com/twowater/mtest1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +# 旧式类 +class OldClass: + def __init__(self, account, name): + self.account = account; + self.name = name; + + +# 新式类 +class NewClass(object): + def __init__(self, account, name): + self.account = account; + self.name = name; + + +if __name__ == '__main__': + old_class = OldClass(111111, 'OldClass') + print(old_class) + print(type(old_class)) + print(dir(old_class)) + print('\n') + new_class=NewClass(222222,'NewClass') + print(new_class) + print(type(new_class)) + print(dir(new_class)) diff --git a/Code/Python9Code/com/twowater/mtest2.py b/Code/Python9Code/com/twowater/mtest2.py new file mode 100644 index 0000000..b320ac3 --- /dev/null +++ b/Code/Python9Code/com/twowater/mtest2.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +class UserInfo(object): + name = '两点水' + + +class UserInfo(object): + def __init__(self, name): + self.name = name + + +class UserInfo(object): + def __init__(self, name, age, account): + self.name = name + self._age = age + self.__account = account diff --git a/Code/Python9Code/com/twowater/mtest3.py b/Code/Python9Code/com/twowater/mtest3.py new file mode 100644 index 0000000..5ae7048 --- /dev/null +++ b/Code/Python9Code/com/twowater/mtest3.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +class UserInfo(object): + def __init__(self, name, age, account): + self.name = name + self._age = age + self.__account = account + + def get_account(self): + return self.__account + + +if __name__ == '__main__': + userInfo = UserInfo('两点水', 23, 347073565); + # 打印所有属性 + print(dir(userInfo)) + # 打印构造函数中的属性 + print(userInfo.__dict__) + print(userInfo.get_account()) + # 用于验证双下划线是否是真正的私有属性 + print(userInfo._UserInfo__account) diff --git a/Code/Python9Code/com/twowater/mtest4.py b/Code/Python9Code/com/twowater/mtest4.py new file mode 100644 index 0000000..d7d0d49 --- /dev/null +++ b/Code/Python9Code/com/twowater/mtest4.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +class User(object): + def upgrade(self): + pass + + def _buy_equipment(self): + pass + + def __pk(self): + pass + diff --git a/Code/Python9Code/com/twowater/mtest5.py b/Code/Python9Code/com/twowater/mtest5.py new file mode 100644 index 0000000..75736fb --- /dev/null +++ b/Code/Python9Code/com/twowater/mtest5.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +class UserInfo(object): + lv = 5 + + def __init__(self, name, age, account): + self.name = name + self._age = age + self.__account = account + + def get_account(self): + return self.__account + + @classmethod + def get_name(cls): + return cls.lv + + @property + def get_age(self): + return self._age + + +if __name__ == '__main__': + userInfo = UserInfo('两点水', 23, 347073565); + # 打印所有属性 + print(dir(userInfo)) + # 打印构造函数中的属性 + print(userInfo.__dict__) + # 直接使用类名类调用,而不是某个对象 + print(UserInfo.lv) + # 像访问属性一样调用方法(注意看get_age是没有括号的) + print(userInfo.get_age) diff --git a/Code/Python9Code/com/twowater/mtest6.py b/Code/Python9Code/com/twowater/mtest6.py new file mode 100644 index 0000000..12474fa --- /dev/null +++ b/Code/Python9Code/com/twowater/mtest6.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +# -*- coding: UTF-8 -*- + +class UserInfo(object): + lv = 5 + + def __init__(self, name, age, account): + self.name = name + self._age = age + self.__account = account + + def get_account(self): + return self.__account + + @classmethod + def get_name(cls): + return cls.lv + + @property + def get_age(self): + return self._age + + +class UserInfo2(UserInfo): + def __init__(self, name, age, account, sex): + super(UserInfo2, self).__init__(name, age, account) + self.sex = sex; + + +if __name__ == '__main__': + userInfo2 = UserInfo2('两点水', 23, 347073565, '男'); + # 打印所有属性 + print(dir(userInfo2)) + # 打印构造函数中的属性 + print(userInfo2.__dict__) + print(UserInfo2.get_name()) diff --git a/Code/Python9Code/com/twowater/mtest7.py b/Code/Python9Code/com/twowater/mtest7.py new file mode 100644 index 0000000..9d6b56a --- /dev/null +++ b/Code/Python9Code/com/twowater/mtest7.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +class UserInfo(object): + lv = 5 + + def __init__(self, name, age, account): + self.name = name + self._age = age + self.__account = account + + def get_account(self): + return self.__account + + +class UserInfo2(UserInfo): + pass + + +if __name__ == '__main__': + userInfo2 = UserInfo2('两点水', 23, 347073565); + print(userInfo2.get_account()) + diff --git a/Code/Python9Code/com/twowater/mtest8.py b/Code/Python9Code/com/twowater/mtest8.py new file mode 100644 index 0000000..1289281 --- /dev/null +++ b/Code/Python9Code/com/twowater/mtest8.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +# -*- coding: UTF-8 -*- + +class User1(object): + pass + + +class User2(User1): + pass + + +class User3(User2): + pass + + +if __name__ == '__main__': + user1 = User1() + user2 = User2() + user3 = User3() + # isinstance()就可以告诉我们,一个对象是否是某种类型 + print(isinstance(user3, User2)) + print(isinstance(user3, User1)) + print(isinstance(user3, User3)) + # 基本类型也可以用isinstance()判断 + print(isinstance('两点水', str)) + print(isinstance(347073565, int)) + print(isinstance(347073565, str)) diff --git a/Code/Python9Code/com/twowater/mtest9.py b/Code/Python9Code/com/twowater/mtest9.py new file mode 100644 index 0000000..f84240b --- /dev/null +++ b/Code/Python9Code/com/twowater/mtest9.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# -*- coding: UTF-8 -*- + +class User(object): + def __init__(self, name): + self.name = name + + def printUser(self): + print('Hello !' + self.name) + + +class UserVip(User): + def printUser(self): + print('Hello ! 尊敬的Vip用户:' + self.name) + + +class UserGeneral(User): + def printUser(self): + print('Hello ! 尊敬的用户:' + self.name) + + +def printUserInfo(user): + user.printUser() + + +if __name__ == '__main__': + userVip = UserVip('两点水') + printUserInfo(userVip) + userGeneral = UserGeneral('水水水') + printUserInfo(userGeneral)