粗略看了下a byte of python,总结一下大致与java不同的地方:1、没有{},全部使用:和缩进代替2、注释使用#3、doc使用"""或者"""4、变量类型比较简单,类似于js,不过定义更像vb或者groovy方法使用def来定义,只有整形,长整形,复数,浮点4种类型的数5、比java更是一切都是对象,连int也是6、输出更像是c7、数组,list,map比较像js8、有 this,改叫self了,而且还必须手动传,必须在第一个。。。9、构造叫init,回收叫del10、继承使用(),需要手动地调用父类的构造随便放段code
04 | def __init__(self, name): |
07 | print "(Initializing %s)" % self.name |
10 | Person.population += 1 |
14 | print "%s says bye." % self.name |
15 | Person.population -= 1 |
16 | if Person.population == 0: |
17 | print "I am the last one." |
19 | print "There are still %d people left." % Person.population |
24 | print "Hi, my name is %s." % self.name |
28 | if Person.population == 1: |
29 | print "I am the only person here." |
31 | print "We have %d persons here." % Person.population |