已采纳回答 / kurio
要么缩进问题s = set(['Adam', 'Lisa', 'Paul']) L = ['Adam', 'Lisa', 'bart', 'Paul'] for i in L: if i in s: s.remove(i) else: s.add(i)print(s)结果:{'bart'}
2016-03-29
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print x[0]+':',x[1]
在想知道相关结果是什么数据类型时,使用type(x)----比如想知道x的数据类型
for x in s:
print x[0]+':',x[1]
在想知道相关结果是什么数据类型时,使用type(x)----比如想知道x的数据类型
2016-03-29
months = set(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])
x1 = 'Feb'
x2 = 'Sun'
if x1 or x2 in months:
print 'x: ok'
else:
print 'x1: error'
x1 = 'Feb'
x2 = 'Sun'
if x1 or x2 in months:
print 'x: ok'
else:
print 'x1: error'
2016-03-29
s = set(['Adam','Lisa','Bart','Paul'])
print'adam'.capitalize ()in s
print 'bart'.capitalize ()in s
xx.upper()全部变大写 xx.lower()全部变小写xx.capitalize()首字母变大写xx.title()是-----'abc bCd'.title()='Abc Bcd'
print'adam'.capitalize ()in s
print 'bart'.capitalize ()in s
xx.upper()全部变大写 xx.lower()全部变小写xx.capitalize()首字母变大写xx.title()是-----'abc bCd'.title()='Abc Bcd'
2016-03-29
def greet(str='world'):
print "Hello, {0}.".format(str)
greet()
greet('Bart')
print "Hello, {0}.".format(str)
greet()
greet('Bart')
2016-03-29
@huangjunli
for x in [ 1,2,3,4,5,6,7,8,9 ]:
for y in [ 1,2,3,4,5,6,7,8,9 ]:
if x < y:
print x*10+y
for x in [ 1,2,3,4,5,6,7,8,9 ]:
for y in [ 1,2,3,4,5,6,7,8,9 ]:
if x < y:
print x*10+y
2016-03-29
已采纳回答 / 清波
这句话是给python 解释器看的, 需要注意两点:1.必须将编码注释放在第一行或者第二行2.可选格式有:<...code...><...code...><...code...>官方文档如下:https://www.python.org/dev/peps/pep-0263/
2016-03-29
for x in [ '1','2','3','4','5','6','7','8','9']:
for y in [ '2','3','4','5','6','7','8','9' ]:
if x>=y:
continue
print x+y
for y in [ '2','3','4','5','6','7','8','9' ]:
if x>=y:
continue
print x+y
2016-03-29
已采纳回答 / 清波
就像练习里要求的那样:针对下面的set,给定一个list,对list中的每一个元素,如果在set中,就将其删除,如果不在set中,就添加进去。<...code...>所以随后set 中只剩下一个,原本不在 set 中的 'Bart'
2016-03-29