来试试这个
L = [95.5, 85, 59]
for i in range(len(L)-1,-1,-1):
print L[i]
L = [95.5, 85, 59]
for i in range(len(L)-1,-1,-1):
print L[i]
2018-04-26
#-*- coding:utf-8 -*-
sum = 0
x = 1
while x < 100: #sum存储x的值,每次循环都递增
sum = sum + x #效果:1+3+5+7+9……99
x = x + 2 #小于100则x每次加2
print sum
sum = 0
x = 1
while x < 100: #sum存储x的值,每次循环都递增
sum = sum + x #效果:1+3+5+7+9……99
x = x + 2 #小于100则x每次加2
print sum
2018-04-26
L = [75, 92, 59, 68] #数组4个分数
sum = 0.0 #定义浮点数
for x in L: #每次循环的分数
sum = sum + x #比如第一次是75,第二次就是75+92,第三次167+59……尾部自然结束
print sum / 4 #除以4得到平均数
sum = 0.0 #定义浮点数
for x in L: #每次循环的分数
sum = sum + x #比如第一次是75,第二次就是75+92,第三次167+59……尾部自然结束
print sum / 4 #除以4得到平均数
2018-04-26
def move(n, a, b, c):
if n == 1:
print a + '-->' + c
return
move(n-1, a, c, b)
move(1, a, b, c)
move(n-1, b, a, c)
if n == 1:
print a + '-->' + c
return
move(n-1, a, c, b)
move(1, a, b, c)
move(n-1, b, a, c)
2018-04-26
print r'''"to be, or not to be":that is the question.
whether it's nobler in the mind to suffer.'''
whether it's nobler in the mind to suffer.'''
2018-04-26
因为第一次L.pop(2)的时候,数组的范围已经变成0-2了,那个L.pop(3)压根就超过范围了,Bart这菜B的位置已经变成2了。
2018-04-26
print [a*100+b*10+c for a in range(1,10) for b in range(0,10) for c in range(0,10) if a == c]
2018-04-26
s = 'Python was started in 1989 by\"Guido\".\nPython is free and easy to learn.'
print s
少一个句号都会错
print s
少一个句号都会错
2018-04-26
'hello,', a or 'world' #显示"hello,",py跟wo做或运算,即1or1,对则显示前者,不对则显示后者。
2018-04-26
写汇编的时候都没那么多布尔运算哈。。。可能没涉及到而已吧。。
是否可以把与运算理解为2进制的乘法。。
1X1=1 1X0=0 0X1=0 0X0=0
是否可以把与运算理解为2进制的乘法。。
1X1=1 1X0=0 0X1=0 0X0=0
2018-04-26
def greet(s='world'):
#print 'hello,'+s+'.'
print 'hello,',s+'.'
greet()
greet('Bart')
#print 'hello,'+s+'.'
print 'hello,',s+'.'
greet()
greet('Bart')
2018-04-26