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.'''哈哈,这一课竟然钻牛角尖了...纠结了半天
2016-02-21
sum = 0
n = 1
while True:
if n > 20:
break
sum += 2**(n-1)
n += 1
print sum
n = 1
while True:
if n > 20:
break
sum += 2**(n-1)
n += 1
print sum
2016-02-20
print 45678 + 0x12fd2
print 'Learn Python in imooc'
print 100 < 99
print 0xff == 255
print 'Learn Python in imooc'
print 100 < 99
print 0xff == 255
2016-02-20
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print index+1, '-', name
for t in enumerate(L):
index=t[0]+1
name=t[1]
print index,'-',name
for index,name in zip(range(1,len(L)+1),L):
print index,'-',name
for index, name in enumerate(L):
print index+1, '-', name
for t in enumerate(L):
index=t[0]+1
name=t[1]
print index,'-',name
for index,name in zip(range(1,len(L)+1),L):
print index,'-',name
for i in range(0,101,7):
print i
for i in range(1,101)[6::7]:
print i
for i in range(1,101):
if i%7==0:
print i
print i
for i in range(1,101)[6::7]:
print i
for i in range(1,101):
if i%7==0:
print i
返回一个仅首字母变成大写的字符串
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2016-02-20
L = range(1, 101)
print L[-10:]
print L[4::5][-10:]
print L[-46::5]
print L[-10:]
print L[4::5][-10:]
print L[-46::5]
dict的第三个特点是作为 key 的元素必须不可变,Python的基本类型如字符串、整数、浮点数都是不可变的,都可以作为 key。但是list是可变的,就不能作为 key
2016-02-19
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:',d['Adam']
print 'Lisa:',d['Lisa']
print 'Bart:',d['Bart']
print 'Adam:',d.get('Adam')
print 'Lisa:',d.get('Lisa')
print 'Bart:',d.get('Bart')
for key,value in d.items():
print '%s: %d'%(key,value)
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:',d['Adam']
print 'Lisa:',d['Lisa']
print 'Bart:',d['Bart']
print 'Adam:',d.get('Adam')
print 'Lisa:',d.get('Lisa')
print 'Bart:',d.get('Bart')
for key,value in d.items():
print '%s: %d'%(key,value)
2016-02-19