也可以从索引1开始,取出2个元素出来:
>>> L[1:3]
['Adam', 'Lisa']
这里的讲解,有错误,根据实际测试,答案为['Lisa', 'Bart']
>>> L[1:3]
['Adam', 'Lisa']
这里的讲解,有错误,根据实际测试,答案为['Lisa', 'Bart']
2015-07-24
def firstCharUpper(s):
return s.capitalize()
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s.capitalize()
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-07-23
def firstCharUpper(s):
return s.upper()[0:1]+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s.upper()[0:1]+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-07-23
def average(*args):
sum=0.0
n=0.0
for x in args:
sum=sum+x
n=n+1.0
if n==0:
return 0.0
else:
return sum/n
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum=0.0
n=0.0
for x in args:
sum=sum+x
n=n+1.0
if n==0:
return 0.0
else:
return sum/n
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-07-23
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
2015-07-23
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for v in d.itervalues():
sum+=v
print sum/len(d)
sum = 0.0
for v in d.itervalues():
sum+=v
print sum/len(d)
2015-07-23