python--php 比较
类:PHP:
class spc_core
{
public $var1;
private $var2;
protected $var3;
public function __construct($v1,$v2){
$this->$var1 = $v1;
$this->$var2 = $v2;
}
}
##############################################################
PYTHON:
class FooClass(object):
version = 0.1 #class (data) attribute
def __init__(self,nm='John Doe'):
self.name=nm #class instance (data) attribute
print 'Created a> def showname(self):
print 'Your name is ',self.name
print 'My name is ',self.__class__.__name__
def showver(self):
print self.version
def addMe2Me(self,x):
print x, '+', x,'=',
return x + x
BB =FooClass()
BB.showname()
BB.showver()
print BB.addMe2Me(9)
print BB.addMe2Me('gg')
页:
[1]