![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
文章平均质量分 57
bean244
这个作者很懒,什么都没留下…
展开
-
Raise and Handle Exception Demo
import sysclass MyError(Exception): def __init__(self,value): self.value = value def __str__(self): return repr(self.value)try: f = open('new.in') s = f.readline() f.close() i = int(s.st原创 2014-01-02 16:07:38 · 545 阅读 · 0 评论 -
Difference between __str__ and __repr__ in Python
Unless you specifically act to ensure otherwise, most classes don't have helpful results for either:>>> class Sic(object): pass... >>> print str(Sic())__main__.Sic object at 0x8b7d0>>>> print re转载 2014-01-03 16:16:18 · 1385 阅读 · 0 评论 -
python打印所有汉字
for ch in xrange(0x4e00, 0x9fa6): print unichr(ch)转载 2014-01-04 15:45:46 · 1307 阅读 · 0 评论 -
python one-line list comprehension: if-else variants
It's more about python list comprehension syntax. I've got a list comprehension that produces list of odd numbers of a given range:[x for x in range(1, 10) if x % 2]This makes a filter - I've go转载 2014-01-20 10:09:06 · 3044 阅读 · 0 评论 -
Are there dictionary comprehensions in Python? (Problem with function returning dict)
I know about list comprehensions, what about dictionary comprehensions?Expected Output:>>> countChar('google') {'e': 1, 'g': 2, 'l': 1, 'o': 2} >>> countLetters('apple') {'a': 1, 'e'转载 2014-01-20 10:14:13 · 776 阅读 · 0 评论 -
A Guide to Python's Magic Methods
Rafe KettlerCopyright © 2012 Rafe KettlerVersion 1.17A PDF version of this guide can be obtained from my site or Github. The magic methods guide has a git repository at http://www.github转载 2014-03-04 09:45:41 · 745 阅读 · 0 评论 -
python中类属性和数据属性的解释
python中的类叫class object,类的实例叫instance object. 类 Class Objects 类拥有两种操作,1.类属性 attribute references 2.实例化instantiation 类属性就相当于专属于一个类的变量(即某些语言中的类的静态公共变量static public),使用方法是:类名称.类属性名称 实例化则是创建一个类的实例的转载 2014-03-04 09:48:20 · 5571 阅读 · 0 评论