python 学习笔记 持续更新中
2013-11-05 22:48
447 查看
1. python 数组的下标是可以小于零的
_del_方法
类似于object-c 中的delloc 方法,对象消失的时候调用,而不是自己调用5.python 可以有多重继承
#!/usr/bin/python # Filename: seq.py shoplist = ['apple', 'mango', 'carrot', 'banana'] # Indexing or 'Subscription' operation print 'Item 0 is', shoplist[0] #apple print 'Item 1 is', shoplist[1] #mango print 'Item -1 is', shoplist[-1] #banana print 'Item -2 is', shoplist[-2] #carrot2. 对象的赋值
print 'Simple Assignment' shoplist = ['apple', 'mango', 'carrot', 'banana'] mylist = shoplist # mylist is just another name pointing to the same object! del shoplist[0] print 'shoplist is', shoplist print 'mylist is', mylist # notice that both shoplist and mylist both print the same list without # the 'apple' confirming that they point to the same object print 'Copy by making a full slice' mylist = shoplist[:] # make a copy by doing a full slice del mylist[0] # remove first item print 'shoplist is', shoplist print 'mylist is', mylist # notice that now the two lists are different3. 字符处理(join 方法类似JS)
delimiter = '_*_' mylist = ['Brazil', 'Russia', 'India', 'China'] print delimiter.join(mylist)4.
_del_方法
类似于object-c 中的delloc 方法,对象消失的时候调用,而不是自己调用5.python 可以有多重继承
class SchoolMember: '''Represents any school member.''' def __init__(self, name, age): self.name = name self.age = age print '(Initialized SchoolMember: %s)' % self.name def tell(self): '''Tell my details.''' print 'Name:"%s" Age:"%s"' % (self.name, self.age), class Teacher(SchoolMember): '''Represents a teacher.''' def __init__(self, name, age, salary): SchoolMember.__init__(self, name, age) self.salary = salary print '(Initialized Teacher: %s)' % self.name def tell(self): SchoolMember.tell(self) print 'Salary: "%d"' % self.salary6. 异常是try except 而 非try catch
try: s = raw_input('Enter something --> ') if len(s) < 3: raise ShortInputException(len(s), 3) # Other work can continue as usual here except EOFError: print '\nWhy did you do an EOF on me?' except ShortInputException, x: print 'ShortInputException: The input was of length %d, \ was expecting at least %d' % (x.length, x.atleast) else: print 'No exception was raised.'
相关文章推荐
- python3.4学习笔记(四) 3.x和2.x的区别,持续更新
- Start Python 学习笔记(琐碎知识,持续更新。。。)
- 持续更新:Python学习笔记
- 线程池原理及python实现学习笔记-持续更新
- python3.4学习笔记(六) 常用快捷键使用技巧,持续更新
- Python学习笔记【持续更新】
- [Python] Python学习笔记之常用模块总结[持续更新...]
- [置顶] 【Python学习笔记】-Python思维导图合集【持续更新】
- Python学习笔记——持续更新
- Python开发实战学习笔记(持续更新)
- 【Python】【学习笔记】持续更新
- Python学习笔记(持续更新)
- Python学习笔记(持续更新中)
- Semantic ui 学习笔记 持续更新
- AIX命令学习笔记【持续更新】
- linux命令学习笔记-持续更新版
- 【学习笔记】JMX1.4总结(持续更新)
- js学习资料笔记合集,持续学习更新中,欢迎大牛们指点
- (转载)cocos2d-x学习笔记(持续更新)
- [持续更新]JavaScript学习笔记(八)