如果使用print [x+y+z for x in '123456789' for y in '1234567890' for z in '123456789' if x==z ]
则出来的结果是字符型,比如'111'而不是111
则出来的结果是字符型,比如'111'而不是111
2019-08-29
版本python3,很不一样
#Enter a code
print(45678+0x12fd2)
print('learn python in imooc')
print(100<99)
print(0xff==255)
#Enter a code
print(45678+0x12fd2)
print('learn python in imooc')
print(100<99)
print(0xff==255)
2019-08-29
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 == z]
2019-08-28
def move(n, a, b, c):
if n==1:
print a+'-->'+c
return
elif n==2:
print a+'-->'+b
print a+'-->'+c
print b+'-->'+c
return
else:
move(n-1,a,c,b)
print a+'-->'+c
move(n-1,b,a,c)
return
move(4, 'A', 'B', 'C')
if n==1:
print a+'-->'+c
return
elif n==2:
print a+'-->'+b
print a+'-->'+c
print b+'-->'+c
return
else:
move(n-1,a,c,b)
print a+'-->'+c
move(n-1,b,a,c)
return
move(4, 'A', 'B', 'C')
2019-08-28
L = [x for x in range(0,101)]
def sum(n):
result = 0
for i in n:
result+= i*i
return result
print sum(L)
def sum(n):
result = 0
for i in n:
result+= i*i
return result
print sum(L)
2019-08-28
for x in range(10,100):
x = list(str(x))
if int(x[0]) < int(x[1]):
print(int(''.join(x)))
x = list(str(x))
if int(x[0]) < int(x[1]):
print(int(''.join(x)))
2019-08-28
print('hello,python')
print'hello,''python'
print'hello,''python'
2019-08-27
按照参考答案,会出现报错:
运行失败
Traceback (most recent call last):
File "index.py", line 8, in
低头思故乡。'''
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
如果把 u 去掉,可以正常运行。
运行失败
Traceback (most recent call last):
File "index.py", line 8, in
低头思故乡。'''
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
如果把 u 去掉,可以正常运行。
2019-08-27
1. if 后面跟的return要缩进
2. print '\n'.join('%s'% id for score in tds)
2. print '\n'.join('%s'% id for score in tds)
2019-08-26