- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass.py
More file actions
Latest commit
19 lines (19 loc) · 642 Bytes
/
Copy pathClass.py
File metadata and controls
19 lines (19 loc) · 642 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
classCalculator:
# 固有属性
name='Good Calculator'
price=18
# 功能
# init函数,构造函数
# 可以用来初始化属性
# 可以设置默认参数
def__init__(self,name,price=1,height=2,width=3):
self.name=name
self.price=price
self.hight=height
self.width=width
defadd(self,x,y):
# 引入self,这样可以调用类内的属性
# 类外用.就可以调用,类内用self调用
print(self.name)
defminus(self,x,y):
print(self.name)