变量弱类型,无需显式声明。
a = 1 b = 2 c = a + b print c
def add(x, y): z = x + y return z
算术运算符:
+, -, *, /, **(幂), //(除取整)
+=, -=, *=, /=, %
逻辑运算符:
and, or, not
and/or操作不返回bool值,返回实际比较值之一
关系运算符:
==, !=, >, <, >=, <=
身份运算符:
is 表示两个对象变量是否指向内存中的同一个对象。
if a > 0: print "positive" elif a == 0: print "zero" else: print "negative"
count = 0 while (count < 9): print ‘The count is:‘, count count = count + 1 for i in range (1, 100, 1): print "count ", i if i == 50: continue if i == 90: break
class human: def __init__(self, name, age): self.name = name self.age = age def detail(self): print "%s %d" %(self.name, self.age)
somebody = human("Jack Wolf",32) somebody.detail()
class woman(human): def __init(self, name, age): human.__init__(self, name, age)
原文:http://my.oschina.net/luckysym/blog/312650