为了账号安全,请及时绑定邮箱和手机立即绑定

初识Python

廖雪峰 移动开发工程师
难度入门
时长 5小时 0分
学习人数
综合评分9.43
3762人评价 查看评价
9.7 内容实用
9.4 简洁易懂
9.2 逻辑清晰

已采纳回答 / 雨林_霖
1,x,y,z的for循环分开3层2,x+y+z是算3个数的和3,x == z包含x==y==z
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print str(x[0]) + ':' + str(x[1])
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key +':' +str(d[key])
a = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for i in L:
if i not in a:
a.add(i)
else:
a.remove(i)
print a
sum = 0
x = 1
n = 1
while True:
sum = sum + x
x = x * 2
n = n + 1
if n > 20:
break
print sum
这样也可以的
在DOS试过了,# -*- coding: utf-8 -*-和u不冲突。尽管# -*- coding: utf-8 -*-已经说明了是按utf-8编码,但是在加一个u并不会出现错误,只是显得有点多余而已。
print [m*100+n*10+k for m in range(1,10) for n in range(0, 10) for k in range(0, 10) if m == k]
顶起,全面,系统
str='<table border="1">\n<tr><th>Name</th><th>Score</th></tr>' +'\n'.join(tds)+('</table>')
with open('test.html', 'w+') as f:
f.write(str)
def generate_tr(name,score):
if score<60:
return '<tr><td>%s</td><td style="color:red">%s</td>' %(name,score)
else:
return '<tr><td>%s</td><td>%s</td>' %(name,score)
tds=[generate_tr(name,score) for name,score in d.items()]
print [int(a+b+c) for a in '123456789' for b in '0123456789' for c in '0123456789' if a==c]
L = [75, 92, 59, 68]
sum = 0.0
for score in L:
sum+=score
print sum / 4
少写个句号你都不pass,这他妈是闹哪样????
我的代码写的比较原始
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum=0
count=0
for score in d.itervalues():
sum=sum+score
count+=1
print sum/(1.0*count)
课程须知
如果您了解程序设计的基本概念,会简单使用命令行,了解中学数学函数的概念,那么对课程学习会有很大的帮助,让您学起来得心应手,快速进入Python世界。
老师告诉你能学到什么?
通过本课程的学习,您将学会搭建基本的Python开发环境,以函数为基础编写完整的Python代码,熟练掌握Python的基本数据类型以及list和dict的操作。

微信扫码,参与3人拼团

微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!

本次提问将花费2个积分

你的积分不足,无法发表

为什么扣积分?

本次提问将花费2个积分

继续发表请点击 "确定"

为什么扣积分?

举报

0/150
提交
取消