s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
continue
s.add(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
continue
s.add(x)
print s
2015-03-15
Python中串联字符串的操作符有两个,一个是"+", 一个是",", "+"不能用来串联非字符串,而","可以!而且","还会输出一个空格
2015-03-15
对list类型,索引迭代用enumate()方法,对dict类型,索引迭代用items()方法,返回的一个是内容为tuple的list.
2015-03-15
score = 85
if score >= 90:
print 'excellent'
elif score >= 80 and score < 90:
print 'good'
elif score >= 70 and score < 80:
print 'passed'
else:
print 'failed'
if score >= 90:
print 'excellent'
elif score >= 80 and score < 90:
print 'good'
elif score >= 70 and score < 80:
print 'passed'
else:
print 'failed'
2015-03-14
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,':',d[key]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,':',d[key]
2015-03-14