面试准备
2016-12-27 18:01
302 查看
值传递和参数传递
>>> a=5 >>> '%.*s' % (a,'fang jia xin') 'fang ' >>> a = 6>>> b = (a,'fang jia xin')>>> '%.*s' % b'fang j'>>> a = 7>>> b(6, 'fang jia xin')
元组的变量传递,是copy后值传递参数
不可变对象传递值,在函数作用域内的改变,不影响函数外变量的值;可变(mutable)对象参数传递,函数可直接更改变量
class Person: name=[] p1=Person() p2=Person() p1.name.append(1) print p1.name # [1] print p2.name # [1] print Person.name # [1]
类变量的传递也类似函数的参数传递
class Person(object): name=[] def __init__(self, xing, ming): self.xing = xing self.ming = ming def __getattr__(self, name): if name == 'fang': print('me')
魔法方法如何重写?是否需要?
super函数的使用?
https://docs.python.org/3.5/library/functions.html?highlight=super#super
getter、setter的使用?
迭代器和生成器
In Python 2.6 and higher, the best way to implement an iterator is generally to use the appropriate abstract base class from the collections standard library module – in Python 2.6, the code might be (remember to call the method next instead in Python 3):import collections class infinite23s(collections.Iterator): def next(self): return 23
构建迭代器最好的方法,重写itertool.collections里的next方法
new & init
Use new when you need to control the creation of a new instance. Use init when you need to control initialization of a new instance.new用来实例化一个类,init用来初始化instance
In general, you shouldn’t need to override new unless you’re subclassing an immutable type like str, int, unicode or tuple.
new的应用:singleton pattern(单例模式)
单例模式,也叫单子模式,是一种常用的软件设计模式。在应用这个模式时,单例对象的类必须保证只有一个实例存在。@singleton class MyClass: #实现单例模式
factory
decorator
super
返回值:Return a proxy object that delegates method calls to a parent or sibling class of type.pdb
从头开始python -m pdb test.py
pdb.run(‘pdb_script.MyObj(5).go()’)
pdb.set_trace()
after failure: pdb.pm()
4.
相关文章推荐
- 面试准备(一)----什么是xxx
- 各种ie6兼容的问题,面试准备
- #面试准备#System Design
- 腾讯面试准备
- 面试准备
- java研发面试准备
- 数据库及常用sql-面试准备
- 面试准备
- 面试准备(常用函数和数据结构)freopen (在程序调试时从文本输入,程序结果放在文本中)
- 面试准备 - Javascript
- 面试准备
- leetcode面试准备:Container With Most Water
- 面试准备
- Java菜鸟的面试准备(一)
- 前段面试准备
- Redis知识点汇总----(面试准备)
- 面试准备(语法类)(int&)a和(int)a的区别
- 阿里数据分析师面试准备二:对阿里数据分析师岗位的理解
- 产品经理面试准备
- leetcode面试准备:Divide Two Integers