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

初识Python

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

已采纳回答 / dooliu
里面封装了i+=1,,而且,Python不支持i++操作,,
L = []
x = 0
while x < 100:
x= x + 1
L= L + [x ** 2]
print (sum(L))
notepad++是在哪里下载的
a = ['jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
months = set(a)
x1 = 'Feb'
x2 = 'Sun'

if x1 in months:
print 'x1: ok'
else:
print 'x1: error'

if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
months = set(['1','2','3','4','5','6','7','8','9','10','11','12'])
x1 = '1'
x2 = 'asdf'

if x1 in months:
print 'x1: ok'
else:
print 'x1: error'

if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
s = 'Python was started in 1989 by "Guido".\nPython is free and easy to learn.'
print [m*100+n*10+m for m in range(1,10) for n in range(0,10)]
推荐大家用pycharm
ef 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()]
import math

def quadratic_equation(a, b, c):
x1=(-b+math.sqrt(b*b-4*a*c))/(2.0*a)
x2=(-b-math.sqrt(b*b-4*a*c))/(2.0*a)
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
利用values来反向查询key
>>> d1={'a':1,'b':2}
>>> {value:key for key,value in d1.iteritems()}[2]

如果有重复的key
>>> d1={'a':1,'b':2,'c':1}
>>> import collections
>>> d=collections.defaultdict(list)
>>> for k,v in d1.iteritems():
... d[v].append(k)
>>> d
defaultdict(<type 'list'>, {1: ['a', 'c'], 2: ['b']})
垃圾测评,毁我青春
def generate_tr(name, score):
if score >= 60:
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
else:
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)

tds = [generate_re(name, score) for name, score in d.iteritems()]
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for k, v in d.items():
print "%s: %s" % (k, v)
isinstance(object,class-or-type-or-tuple)--> bool ,判断一个object是否属于后面的类型~返回True或者False
课程须知
如果您了解程序设计的基本概念,会简单使用命令行,了解中学数学函数的概念,那么对课程学习会有很大的帮助,让您学起来得心应手,快速进入Python世界。
老师告诉你能学到什么?
通过本课程的学习,您将学会搭建基本的Python开发环境,以函数为基础编写完整的Python代码,熟练掌握Python的基本数据类型以及list和dict的操作。

微信扫码,参与3人拼团

微信客服

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

帮助反馈 APP下载

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

公众号

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

友情提示:

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

本次提问将花费2个积分

你的积分不足,无法发表

为什么扣积分?

本次提问将花费2个积分

继续发表请点击 "确定"

为什么扣积分?

举报

0/150
提交
取消