L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print index+1, '-', name
for index, name in enumerate(L):
print index+1, '-', name
L = ['Adam', 'Lisa', 'Bart', 'Paul']
A = range(1,5)
B =zip(A,L)
for index, name in B:
print index, '-', name
A = range(1,5)
B =zip(A,L)
for index, name in B:
print index, '-', name
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-08-19
def average(*args):
if len(args)==0:
return 0.0
else:
return (sum(args)*1.0)/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args)==0:
return 0.0
else:
return (sum(args)*1.0)/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2019-08-19
L = [75, 92, 59, 68]
sum = 0.0
for x in L:
sum+=x
print sum / 4
sum = 0.0
for x in L:
sum+=x
print sum / 4
2019-08-18
print [100*a+10*b+a for a in range(1,10) for b in range(10) ]
第三位直接用a就行,省了if语句
第三位直接用a就行,省了if语句
2019-08-16
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.'''
2019-08-16
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. '''
2019-08-16
L = []
a = 1
n = 100
while a <= n:
L.append(a*a)
a+=1
print sum(L)
a = 1
n = 100
while a <= n:
L.append(a*a)
a+=1
print sum(L)
2019-08-16
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
2019-08-16
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:'+str(d.get('Adam'))
print 'Lisa:'+str(d.get('Lisa'))
print 'Bart:'+str(d.get('Bart'))
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:'+str(d.get('Adam'))
print 'Lisa:'+str(d.get('Lisa'))
print 'Bart:'+str(d.get('Bart'))
2019-08-15