L = ['Adam', 95.5, 'Lisa', 85, 'Bart', 59]
print L
print L
2019-10-06
x1 = 1
d = 3
n = 100
x100 =(n-1)*d+1
s = (x100+x1)*(n/2)
print s
d = 3
n = 100
x100 =(n-1)*d+1
s = (x100+x1)*(n/2)
print s
2019-10-06
类似二维数组
t[2][0]='X'
t[2][1]='Y'
效果一样
t[2][0]='X'
t[2][1]='Y'
效果一样
2019-10-04
L = [75, 92, 59, 68]
sum = 0.0
for score in L:
sum=sum+score
print sum / 4
sum = 0.0
for score in L:
sum=sum+score
print sum / 4
2019-10-03
Python把0、空字符串''和None看成 False,其他数值和非空字符串都看成 True.
1.计算a and b时 如果a是false则输出false。
2.计算a or b时 如果a是ture则输出ture。
1.计算a and b时 如果a是false则输出false。
2.计算a or b时 如果a是ture则输出ture。
2019-10-03
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k,':',str(v)
print 'average', ':', sum / len(d)
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k,':',str(v)
print 'average', ':', sum / len(d)
2019-10-02
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-10-02
# -*- coding: utf-8 -*-
import sys;
reload(sys);
sys.setdefaultencoding("utf8")
print u'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
import sys;
reload(sys);
sys.setdefaultencoding("utf8")
print u'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
2019-09-30
def square_of_sum(L):
s = []
for f in L :
s.append(f*f)#平方后赋值给新的list
return sum(s)//求和
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
s = []
for f in L :
s.append(f*f)#平方后赋值给新的list
return sum(s)//求和
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2019-09-28
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for k,v in d.items():
print(k+':'+str(v))
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for k,v in d.items():
print(k+':'+str(v))
2019-09-27