会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
Smalllv
博客园
首页
新随笔
联系
订阅
管理
上一页
1
2
3
下一页
2018年4月20日
继承
摘要: class Zoo(): 2 def sleep(self): 3 print('---睡觉---') 4 def eat(self): 5 print('---吃----') 6 def run(self): 7 print('--跑--') 8 class Dog(Zoo): 9 ...
阅读全文
posted @ 2018-04-20 11:17 Smalllv
阅读(90)
评论(0)
推荐(0)
编辑
__del__的应用
摘要:
阅读全文
posted @ 2018-04-20 01:07 Smalllv
阅读(77)
评论(0)
推荐(0)
编辑
2018年4月19日
私有方法 练习
摘要: 1 class Dog: 2 3 #私有方法 4 def __test(self): #私有方法 ‘前面加————’ 5 print('--------出货中-------') 6 7 #共有方法 8 def test(self,money): 9 if money>10000...
阅读全文
posted @ 2018-04-19 23:42 Smalllv
阅读(86)
评论(0)
推荐(0)
编辑
面向对象 练习 新房加家具
摘要: 1 class Home: 2 def __init__(self,new_area,new_addr,new_price): 3 self.area = new_area 4 self.addr = new_addr 5 self.price = new_price 6 self.resarea =...
阅读全文
posted @ 2018-04-19 18:20 Smalllv
阅读(123)
评论(0)
推荐(0)
编辑
面向对象练习 ,烤土豆
摘要: 1 #定义个类 2 class SweetPatato: 3 #初始化 4 def __init__(self): 5 self.status = '生的' 6 self.biaozhi = 0 7 self.flavour = [] 8 9 def __str__(self): 10...
阅读全文
posted @ 2018-04-19 14:23 Smalllv
阅读(144)
评论(0)
推荐(0)
编辑
__init__ 和 __str__
摘要: 1 #定义一个类 2 class Cat: 3 #初始化 4 def __init__(self,new_name,new_age): 5 self.name = new_name 6 self.age = new_age 7 8 def __str__(self): 9 return(...
阅读全文
posted @ 2018-04-19 12:10 Smalllv
阅读(310)
评论(0)
推荐(0)
编辑
创建对象,添加属性,创建多个对象
摘要: 1 #定义一个类 2 class Cat: 3 #属性 4 5 6 #方法 7 def eat(self): 8 print('猫在吃鱼。。。') 9 10 def drink(self): 11 print('喝水。。') 12 #第二种显示 13 def intr...
阅读全文
posted @ 2018-04-19 00:52 Smalllv
阅读(514)
评论(0)
推荐(0)
编辑
2018年4月18日
复制文件
摘要: 1 #复制文件,并且复制后的文件名为xxx[复件].py 2 #列 test.py 复制后 test[复件].py 3 4 5 #获取文件名 6 old_file = input('输入要复制的文件名:') 7 8 #读取文件 9 ofile = open(old_file,'r') 10 cfile = ofile.read() 11 12...
阅读全文
posted @ 2018-04-18 17:27 Smalllv
阅读(132)
评论(0)
推荐(0)
编辑
num+=num 与 num = num+num
摘要: 1 a = [100] 2 3 def test(num): 4 #num+=num #如果num是可变类型,修改它。如果是不可变类型,重新指向一 个内存地址并赋值。 5 6 num = num+num # 直接重新指向一个内存地址,赋予num。 num+=num和num = nu ...
阅读全文
posted @ 2018-04-18 13:01 Smalllv
阅读(763)
评论(0)
推荐(0)
编辑
交换2个变量
摘要: 1 a = 3 2 b = 4 3 4 #a,b交换让a = 4,b = 3. 5 6 #第一种 7 8 #c = 0 9 #c = a 10 #a = b 11 #b = c 12 13 14 15 #第二种 16 #a = a+b 17 #b = a-b 18 #a = a-b 19 20 21 #第三种 22 ...
阅读全文
posted @ 2018-04-18 12:39 Smalllv
阅读(87)
评论(0)
推荐(0)
编辑
上一页
1
2
3
下一页
公告