d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for x in d.itervalues():
sum=sum+x
print sum/len(d)
sum = 0.0
for x in d.itervalues():
sum=sum+x
print sum/len(d)
2019-01-15
L = ['Adam', 'Lisa', 'Bart', 'Paul']
LL=range(1,5)
for index, name in zip(LL,L):
print index, '-', name
LL=range(1,5)
for index, name in zip(LL,L):
print index, '-', name
sum = 0
x = 1
while x < 100:
x%2 == 1
sum = sum + x
x = x + 1
print sum
x = 1
while x < 100:
x%2 == 1
sum = sum + x
x = x + 1
print sum
2019-01-15
L = range(1, 101)//1,2,。。。,100,共100个数,没有101
print L[-10:]
print L[54::5]
# 100-5*9=65-->[64]=[64-100=-46]
最后一个数是:100---对应坐标99,即[99]
第一个数是:100-5*9=55--对应坐标54,即[54]
而总长为100转化倒序时,[54]=[54-100]=[-46]
0 1 2 3 。。。99
-100 -99 -98 -97 。。。 -1
print L[-10:]
print L[54::5]
# 100-5*9=65-->[64]=[64-100=-46]
最后一个数是:100---对应坐标99,即[99]
第一个数是:100-5*9=55--对应坐标54,即[54]
而总长为100转化倒序时,[54]=[54-100]=[-46]
0 1 2 3 。。。99
-100 -99 -98 -97 。。。 -1
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2019-01-15
# -*- coding:UTF-8 -*-
L = range(1, 101)
print L[0:10]
print L[2:100:3] #3就是每隔2个取一个
print L[4:50:5]
L = range(1, 101)
print L[0:10]
print L[2:100:3] #3就是每隔2个取一个
print L[4:50:5]
2019-01-15
def average(*args):
sum=0.0
if len(args)==0:
return 0.0
for x in args:
sum+=x
aver=sum/len(args)
return aver
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum=0.0
if len(args)==0:
return 0.0
for x in args:
sum+=x
aver=sum/len(args)
return aver
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2019-01-15
如果要加u的话,前面加上
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
2019-01-15
def greet(name='world'):
print 'hello, '+name+'.'
greet()
greet('Bart')
print 'hello, '+name+'.'
greet()
greet('Bart')
2019-01-15