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

python进阶

廖雪峰 移动开发工程师
难度中级
时长 3小时33分
学习人数
综合评分9.20
575人评价 查看评价
9.6 内容实用
9.0 简洁易懂
9.0 逻辑清晰
import math

def is_sqr(x):
return True if math.sqrt(x) % 1 == 0 else False

print filter(is_sqr, range(1, 101))
class Person():
name=''
def __init__(self,n):
self.name=n

xiaoming = Person('xm')
xiaohong = Person('xh')

print xiaoming.name
print xiaohong.name
print xiaoming==xiaohong
额。。。视频卡的不要不要的
def cmp_ignore_case(s1, s2):
if s1.upper() > s2.upper():
return 1
if s1.upper() < s2.upper():
return -1
return 0

print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
好绕啊,实际中用得多吗?这种代码可读性不强啊
import math

def add(x, y, f):
return f(x) + f(y)

print add(25, 9, math.sqrt)

最赞回答 / stonewood
这要看不同内置函数的具体定义,<...code...>这样应该很清晰了,查看内置函数的定义用help('内置函数名')
class Person(object):
count = 0
def __init__(self, name):
self.name = name
Person.count = Person.count + 1
print person.__count
p1 = Person(&#039;Bob&#039;)
p2 = Person(&#039;Alice&#039;)
print Person.__count
在编译器中这样执行后:
1
2
AttributeError: type object &#039;Person&#039; has no attribute &#039;__count&#039;
在实际编译器中运行是会自动报attributeerror错误的
import os

print os.path.isdir(r&#039;/data/webroot/resource/python&#039;)
print os.path.isfile(r&#039;/data/webroot/resource/python/test.txt&#039;)

返回是False
class Fib(object):
def __call__(self,number):
x = 0

a,b,L = 0,1,[]
while x&lt;number:
L.append(a)
a,b = b,a+b
x +=1
return L

f = Fib()
print f(10)
L2 = sorted(L1, lambda x, y: -cmp(x.name, y.name))
倒序输出
return &quot;(Student:%s,%s,%d)&quot; % (self.name,self.gender,self.score)

最赞回答 / lhkwqy
你这种方法是最终返回一个列表(列表中有三个值),用闭包的方法返回的是只有一个值的列表,每次调用后产生的结果不同,因为输入的i在变

最新回答 / 昵称叫啥都行
应该Python设计的和其他不一样呗,xxx处是一个固定的,return 的是  a.__cmp__(b)
class Person(object):
def __init__(self,name,gender,**kw):
self.name = name
self.gender = gender
for k in kw:
setattr(self,k,kw[k])
kwargs={&#039;age&#039;:25,&#039;course&#039;:&#039;Python&#039;}
p = Person(&#039;LiLi&#039;,&#039;man&#039;,**kwargs)
print p.name
print p.gender
print p.age
print p.course
课程须知
本课程是Python入门的后续课程 1、掌握Python编程的基础知识 2、掌握Python函数的编写 3、对面向对象编程有所了解更佳
老师告诉你能学到什么?
1、什么是函数式编程 2、Python的函数式编程特点 3、Python的模块 4、Python面向对象编程 5、Python强大的定制类

微信扫码,参与3人拼团

微信客服

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

帮助反馈 APP下载

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

公众号

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

友情提示:

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

本次提问将花费2个积分

你的积分不足,无法发表

为什么扣积分?

本次提问将花费2个积分

继续发表请点击 "确定"

为什么扣积分?

举报

0/150
提交
取消