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

python进阶

廖雪峰 移动开发工程师
难度中级
时长 3小时33分
学习人数
综合评分9.20
575人评价 查看评价
9.6 内容实用
9.0 简洁易懂
9.0 逻辑清晰
def __str__(self):
n = self.gcd(self.p,self.q)
return '%s/%s' % (self.p/n,self.q/n)

def gcd(self,n1,n2):
if n1%n2 == 0:
return n2
return self.gcd(n2,n1%n2)
def __str__(self):
return str(self.fab(self.num))


def __len__(self):
return len(self.fab(self.num))
def __init__(self, num):
self.num = num

def fab(self,count):
L = []
n,a,b = 0,0,1
while n < count-1:
if n== 0:
L.append(a)
L.append(b)
a,b = b,a+b
n += 1
return L
def cmp_ignore_case(s1, s2):
return 1 if s1.lower() > s2.lower() else -1 if s1.lower() < s2.lower() else 0

print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
感觉到python好强大
def __str__(self):
return '(Student: %s, %s, %s)' % (self.name,self.gender,self.score)
def __init__(self, name, gender, **kw):
self.name = name
self.gender = gender
for k,v in kw.items():
setattr(self,k,v)
def __init__(self, name, gender, **kw):
self.name = name
self.gender = gender
for k,v in kw.iteritems():
setattr(Person,k,v)
def __init__(self, name, gender, **kw):
self.name = name
self.gender = gender
if 'age' in kw:
self.age = kw['age']
if 'course' in kw:
self.course = kw['course']
class BStudent(Student,BasketballMixin):
pass

class FTeacher(Teacher,FootballMixin):
pass
class BStudent(BasketballMixin):
pass

class FTeacher(FootballMixin):
pass
import json

class Students(object):
def read(self):
return r'["Tim", "Bob", "Alice"]'


s = Students()

print json.load(s)
class Teacher(Person):

def __init__(self, name, gender, course):
super(Teacher,self).__init__(name,gender)
self.course = course
class Person(object):

__count = 0

@classmethod
def how_many(s):
return s.__count
def __init__(self,name):
self.name = name
Person.__count += 1



print Person.how_many()

p1 = Person('Bob')

print Person.how_many()
def __init__(self, name, score):
self.name = name
self.__score = score

def get_grade(self):
if self.__score > 80:
print self.name,'-','优秀'
elif self.__score > 60:
print self.name,'-','及格'
else:
print self.name,'-','不及格'
课程须知
本课程是Python入门的后续课程 1、掌握Python编程的基础知识 2、掌握Python函数的编写 3、对面向对象编程有所了解更佳
老师告诉你能学到什么?
1、什么是函数式编程 2、Python的函数式编程特点 3、Python的模块 4、Python面向对象编程 5、Python强大的定制类

微信扫码,参与3人拼团

意见反馈 帮助中心 APP下载
官方微信
友情提示:

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

本次提问将花费2个积分

你的积分不足,无法发表

为什么扣积分?

本次提问将花费2个积分

继续发表请点击 "确定"

为什么扣积分?

举报

0/150
提交
取消