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
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for i in L:
if i in s:
s.remove(i)
else:
s.add(i)
print s
2016-01-03
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 + y
for y in ['1','2','3','4','5','6','7','8','9']:
if x < y:
print x + y
2016-01-03
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum = sum + x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum = sum + x
print sum
2016-01-03
def square_of_sum(list):
sum = 0
for x in list:
sum += x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum = 0
for x in list:
sum += x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2016-01-03
擦,原来答案是手动添加小写名字啊?
另外,代码正确与否不是看结果而是直接对比代码语句啊?否则为什么我使用双引号就一直提示错误,而更换单引号就通过了呢?
另外,代码正确与否不是看结果而是直接对比代码语句啊?否则为什么我使用双引号就一直提示错误,而更换单引号就通过了呢?
2016-01-03
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(3)
L.pop(2)
print L
这样也可以啊
L.pop(3)
L.pop(2)
print L
这样也可以啊
2016-01-03
a = 'python'
print 'hello,', a or 'world' # hello, python
因为a = 'python', 根据布尔运算非空字符串等于 true 并且 a 和 'world'做 or 运算,所以返回a,即结果是 hello, python
b = ''
print 'hello,', b or 'world' #hello, world
因为b是空字符串,根据布尔运算空字符串等于false 并且 b 和 'world' 做 or 运算,所以返回 'world',即结果是 hello world
print 'hello,', a or 'world' # hello, python
因为a = 'python', 根据布尔运算非空字符串等于 true 并且 a 和 'world'做 or 运算,所以返回a,即结果是 hello, python
b = ''
print 'hello,', b or 'world' #hello, world
因为b是空字符串,根据布尔运算空字符串等于false 并且 b 和 'world' 做 or 运算,所以返回 'world',即结果是 hello world
2016-01-02
最新回答 / 杰克船长
第一行不是为了注释掉这段代码,是为了提醒编辑器要使用utf-8 ,另外因为这个用的是Python3的编辑器所以里面已经支持自动转换到utf-8的代码了,因此不需要再加u
2016-01-02
print [x*100+y*10+z for x in range(1,10)\
for y in range(0,10)\
for z in range(0,10)\
if x*100+y*10+z == z*100+y*10+x]
for y in range(0,10)\
for z in range(0,10)\
if x*100+y*10+z == z*100+y*10+x]
2016-01-02
print [ (2*(x-1)+1) * ((2*(x-1)+1)+1) for x in range(1,51)]
print [x * (x + 1) for x in range(1, 100, 2)]
print [x * (x + 1) for x in range(1, 100, 2)]