for x in range(1,10):
for y in range(0,10):
if x>y:
continue
print(str(x)+str(y))
...没想到可以利用x+1
for y in range(0,10):
if x>y:
continue
print(str(x)+str(y))
...没想到可以利用x+1
2016-05-14
s = 'Python was started in 1989 by \"Guido\".\n Python is free and easy to learn.'
print s
\n 后有一个空格,第二行与第一行开头是不对=对齐的。
print s
\n 后有一个空格,第二行与第一行开头是不对=对齐的。
2016-05-14
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key, ":", d[key]
注意逗号后最好加一个空格,试下PyCharm这个工具,会给你提示
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key, ":", d[key]
注意逗号后最好加一个空格,试下PyCharm这个工具,会给你提示
2016-05-13
tuple内容不变,原tuple的元素有三个,所以答案里也只能是三个元素。
而如果将['A','B']直接修改为'A','B'的话则修改后的tuple元素有四个,所以是不正确的。
不知道是不是这样。。。
而如果将['A','B']直接修改为'A','B'的话则修改后的tuple元素有四个,所以是不正确的。
不知道是不是这样。。。
2016-05-13
L = [2,4,9,5,8,1,4]
L.sort()
print L
可以排序 但是是对整体的排序 此题既有字符又有数字 会是这种结果[59, 85, 95.5, 'Adam', 'Bart', 'Lisa']
L.sort()
print L
可以排序 但是是对整体的排序 此题既有字符又有数字 会是这种结果[59, 85, 95.5, 'Adam', 'Bart', 'Lisa']
2016-05-13
已采纳回答 / kingstar158
for m in 'ABC' ,for n in '123': 两个for循环中逗号的问题,简单来说就是python的语法格式要求,复杂一点来说就是Python编译器没法识别你的输入
2016-05-13
def generate_tr(name, score):
if (score < 60):
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
tds = [generate_tr(name, score) for name, score in d.iteritems()]
if (score < 60):
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
tds = [generate_tr(name, score) for name, score in d.iteritems()]
2016-05-13
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:
continue
print x+y
for y in [ '0','1','2','3','4','5','6','7','8','9' ]:
if x>=y:
continue
print x+y
2016-05-13
已采纳回答 / 清波
呃。。。 。 关于这个问题,回答了好多好多遍了。。。在Python 交互环境中 (IDLE Shell), 如果一个代码块(解释见下面)输入完毕, 一定要多敲一次回车键,直到 ">>> " 标识出现在写其他代码!<...code...>另,只是在Python 交互式 环境中,才是这样, 正常的Python 文件没有强制要求 代码块下面必须空一行, 但是为了 代码看起来好看, 也建议这么做
2016-05-13
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print('Adam:',d.get('Adam'))
print('Lisa:',d.get('Lisa'))
print('Bart:',d.get('Bart'))
print('Paul:',d.get('Paul'))
Adam: 95
Lisa: 85
Bart: 59
Paul: None
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print('Adam:',d.get('Adam'))
print('Lisa:',d.get('Lisa'))
print('Bart:',d.get('Bart'))
print('Paul:',d.get('Paul'))
Adam: 95
Lisa: 85
Bart: 59
Paul: None
2016-05-12
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-05-12