1、函数:
def foo(debug=True):
if debug:
print ‘in debug modle’
print ‘done’
>>foo()
>>in debug modle
>>done
>>foo(false)
>>done
2、类
class foo(object):
version=0.1#静态变量,可以被方法以及实例共享 def __init__(self,name='TOM'):#name默认值为TOM self.name=name#成员变量,只属于实例 print self.__class__.__name__,'is be created',#slef.__class__.__name__类的名字 def showname(self): print 'your name is',self.name, print 'my name is',self.__class__.__name__, def showver(self): print 'version is',self.version, def mezme(self,x): print x+x,#x只是一个参数而已myclass=foo()myclass.showname()myclass.showver()myclass.mezme(100)
模块
import sys
print sys.out.write('helloword\n')#sys.stdout.write()不自动在结尾加回车,而print要
print sys.platform
print sys.version
3、PEP python Enhancement Proposal (python增强提案)