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.'''
2015-07-29
s = 'Python was started in 1989 by "Guido".\nPython is free and easy to learn.'
print s
print s
2015-07-29
<script>alert('what are you 弄啥嘞');</script>
2015-07-29
要避免 KeyError 发生,有两个办法:
一是先判断一下 key 是否存在,用 in 操作符:
if 'Paul' in d:
print d['Paul']
如果 'Paul' 不存在,if语句判断为False,自然不会执行 print d['Paul'] ,从而避免了错误。
二是使用dict本身提供的一个 get 方法,在Key不存在的时候,返回None:
>>> print d.get('Bart')
59
>>> print d.get('Paul')
None
一是先判断一下 key 是否存在,用 in 操作符:
if 'Paul' in d:
print d['Paul']
如果 'Paul' 不存在,if语句判断为False,自然不会执行 print d['Paul'] ,从而避免了错误。
二是使用dict本身提供的一个 get 方法,在Key不存在的时候,返回None:
>>> print d.get('Bart')
59
>>> print d.get('Paul')
None
2015-07-29
for x in [1,2,3,4,5,6,7,8,9]:
for y in [0,1,2,3,4,5,6,7,8,9]:
if x<y:
print x*10+y
for y in [0,1,2,3,4,5,6,7,8,9]:
if x<y:
print x*10+y
2015-07-29
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
我能说这样也算作弊了么?
x1 = 1
d = 3
n = 100
x100 = x1+(n-1)*d
s = n*(x1+x100)/2
print s
d = 3
n = 100
x100 = x1+(n-1)*d
s = n*(x1+x100)/2
print s
2015-07-28
print 'hello,python.'
print "hello,python."
print 'hello,','python'
print "hello,python."
print 'hello,','python'
2015-07-28
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
2015-07-28