print 3 in [1, 2, 3] # membership (1 means true
inventory = ["sword", "armor", "shield", "healing potion"]
if "healing potion" in inventory:
print "You will live to fight another day."
# 假如某个表有6个字段
# exclude是要排除的字段的数组,其形如["field1","field2","field3"]
# 以下函数是将某个数据库表中全部字段都取出来变成insert时的fields部分如:
# insert table_name (field4,field5,field6) values ....
# 是形成括号内的部分,有时候我们要排除某个字段,以下方法便派上了用场
# 尤其是if descri not in exclude
def getAllFieldsTitle(self, sql, exclude):
self.cursor.execute(sql)
descriptions = self.cursor.description
colNames = []
for i in range(0, len(descriptions)):
descri = descriptions[i][0]
if descri not in exclude:
colNames.append(descri)
fields = ','.join(colNames)
return fields
# 最后输出的结果为:
# field4,field5,field6
应用print 3 in [1, 2, 3] # membership (1 means trueinventory = ["sword", "armor", "shield", "healing potion"]if "healing potion" in inventory: print "You will live to fight another day." # 假如某个表有6个字段 # exclude是要排除的字段的数组,其形如["field1","field2","fiel