Skip to content

Commit 278330d

Browse files
committed
Signed-off-by: twowater <[email protected]>
Python 9 代码
1 parent e5face5 commit 278330d

File tree

17 files changed

+952
-0
lines changed

17 files changed

+952
-0
lines changed

Code/Python9Code/.idea/Python9Code.iml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Code/Python9Code/.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Code/Python9Code/.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Code/Python9Code/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Code/Python9Code/.idea/workspace.xml

Lines changed: 680 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Code/Python9Code/com/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env python
2+
# -*- coding: UTF-8 -*-
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env python
2+
# -*- coding: UTF-8 -*-
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: UTF-8 -*-
3+
4+
class Test:
5+
def prt(self):
6+
print(self)
7+
print(self.__class__)
8+
9+
t = Test()
10+
t.prt()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
# -*- coding: UTF-8 -*-
3+
4+
# 旧式类
5+
class OldClass:
6+
def __init__(self, account, name):
7+
self.account = account;
8+
self.name = name;
9+
10+
11+
# 新式类
12+
class NewClass(object):
13+
def __init__(self, account, name):
14+
self.account = account;
15+
self.name = name;
16+
17+
18+
if __name__ == '__main__':
19+
old_class = OldClass(111111, 'OldClass')
20+
print(old_class)
21+
print(type(old_class))
22+
print(dir(old_class))
23+
print('\n')
24+
new_class=NewClass(222222,'NewClass')
25+
print(new_class)
26+
print(type(new_class))
27+
print(dir(new_class))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python
2+
# -*- coding: UTF-8 -*-
3+
4+
class UserInfo(object):
5+
name = '两点水'
6+
7+
8+
class UserInfo(object):
9+
def __init__(self, name):
10+
self.name = name
11+
12+
13+
class UserInfo(object):
14+
def __init__(self, name, age, account):
15+
self.name = name
16+
self._age = age
17+
self.__account = account
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
# -*- coding: UTF-8 -*-
3+
4+
class UserInfo(object):
5+
def __init__(self, name, age, account):
6+
self.name = name
7+
self._age = age
8+
self.__account = account
9+
10+
def get_account(self):
11+
return self.__account
12+
13+
14+
if __name__ == '__main__':
15+
userInfo = UserInfo('两点水', 23, 347073565);
16+
# 打印所有属性
17+
print(dir(userInfo))
18+
# 打印构造函数中的属性
19+
print(userInfo.__dict__)
20+
print(userInfo.get_account())
21+
# 用于验证双下划线是否是真正的私有属性
22+
print(userInfo._UserInfo__account)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
# -*- coding: UTF-8 -*-
3+
4+
class User(object):
5+
def upgrade(self):
6+
pass
7+
8+
def _buy_equipment(self):
9+
pass
10+
11+
def __pk(self):
12+
pass
13+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python
2+
# -*- coding: UTF-8 -*-
3+
4+
class UserInfo(object):
5+
lv = 5
6+
7+
def __init__(self, name, age, account):
8+
self.name = name
9+
self._age = age
10+
self.__account = account
11+
12+
def get_account(self):
13+
return self.__account
14+
15+
@classmethod
16+
def get_name(cls):
17+
return cls.lv
18+
19+
@property
20+
def get_age(self):
21+
return self._age
22+
23+
24+
if __name__ == '__main__':
25+
userInfo = UserInfo('两点水', 23, 347073565);
26+
# 打印所有属性
27+
print(dir(userInfo))
28+
# 打印构造函数中的属性
29+
print(userInfo.__dict__)
30+
# 直接使用类名类调用,而不是某个对象
31+
print(UserInfo.lv)
32+
# 像访问属性一样调用方法(注意看get_age是没有括号的)
33+
print(userInfo.get_age)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: UTF-8 -*-
3+
4+
class UserInfo(object):
5+
lv = 5
6+
7+
def __init__(self, name, age, account):
8+
self.name = name
9+
self._age = age
10+
self.__account = account
11+
12+
def get_account(self):
13+
return self.__account
14+
15+
@classmethod
16+
def get_name(cls):
17+
return cls.lv
18+
19+
@property
20+
def get_age(self):
21+
return self._age
22+
23+
24+
class UserInfo2(UserInfo):
25+
def __init__(self, name, age, account, sex):
26+
super(UserInfo2, self).__init__(name, age, account)
27+
self.sex = sex;
28+
29+
30+
if __name__ == '__main__':
31+
userInfo2 = UserInfo2('两点水', 23, 347073565, '男');
32+
# 打印所有属性
33+
print(dir(userInfo2))
34+
# 打印构造函数中的属性
35+
print(userInfo2.__dict__)
36+
print(UserInfo2.get_name())
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
# -*- coding: UTF-8 -*-
3+
4+
class UserInfo(object):
5+
lv = 5
6+
7+
def __init__(self, name, age, account):
8+
self.name = name
9+
self._age = age
10+
self.__account = account
11+
12+
def get_account(self):
13+
return self.__account
14+
15+
16+
class UserInfo2(UserInfo):
17+
pass
18+
19+
20+
if __name__ == '__main__':
21+
userInfo2 = UserInfo2('两点水', 23, 347073565);
22+
print(userInfo2.get_account())
23+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: UTF-8 -*-
3+
4+
class User1(object):
5+
pass
6+
7+
8+
class User2(User1):
9+
pass
10+
11+
12+
class User3(User2):
13+
pass
14+
15+
16+
if __name__ == '__main__':
17+
user1 = User1()
18+
user2 = User2()
19+
user3 = User3()
20+
# isinstance()就可以告诉我们,一个对象是否是某种类型
21+
print(isinstance(user3, User2))
22+
print(isinstance(user3, User1))
23+
print(isinstance(user3, User3))
24+
# 基本类型也可以用isinstance()判断
25+
print(isinstance('两点水', str))
26+
print(isinstance(347073565, int))
27+
print(isinstance(347073565, str))
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: UTF-8 -*-
3+
4+
class User(object):
5+
def __init__(self, name):
6+
self.name = name
7+
8+
def printUser(self):
9+
print('Hello !' + self.name)
10+
11+
12+
class UserVip(User):
13+
def printUser(self):
14+
print('Hello ! 尊敬的Vip用户:' + self.name)
15+
16+
17+
class UserGeneral(User):
18+
def printUser(self):
19+
print('Hello ! 尊敬的用户:' + self.name)
20+
21+
22+
def printUserInfo(user):
23+
user.printUser()
24+
25+
26+
if __name__ == '__main__':
27+
userVip = UserVip('两点水')
28+
printUserInfo(userVip)
29+
userGeneral = UserGeneral('水水水')
30+
printUserInfo(userGeneral)

0 commit comments

Comments
 (0)