python
文章平均质量分 74
Mluka
这个作者很懒,什么都没留下…
展开
-
python核心编程中的对象值比较VS对象身份比较
在python核心编程第四章中,P69在优化下面这段代码时提出了:对象值比较VS对象身份比较 在运行时期,只有一个类型对象来表示整形类型。也就是说type(0),type(42),type(-100)都是同一个对象 如果他们是同一个对象,我们为什么还要浪费时间去获得并比较他们的值呢?所以比较对象本身是一个更好的方案。 所以将 if type(num) == types.In原创 2016-04-06 17:28:08 · 844 阅读 · 0 评论 -
Counting Bobs!
在MITx: 6.00.1x Introduction to Computer Science and Programming Using Python的week2-problem set1中有一个有趣的Counting Bobs的习题. 他的要求是: Write a program that prints the number of times the string ‘bob’ occurs原创 2016-04-09 10:50:52 · 414 阅读 · 0 评论