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

python进阶

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

class FTeacher(FootballMixin,Teacher):
pass
import json

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

s = Students()

print json.load(s)
print isinstance(t,Person)
print isinstance(t,Student)
print isinstance(t,Teacher)
print isinstance(t,object)
class Person(object):
def __init__(self, name, gender):
self.name = name
self.gender = gender

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(cls):
return cls.__count

def __init__(self,name):
self.name = name
Person.__count+=1

print Person.how_many()

p1 = Person('Bob')

print Person.how_many()
# -*- coding: UTF-8 -*-
###
def __init__(self, name, score):
self.name = name
self.__score = score

def get_grade(self):
if self.__score>=90:
return 'A-优秀'
elif self.__score>=60:
return 'B-及格'
else:
return 'C-不及格'
class Person(object):

__count = 0

def __init__(self, name):
self.name = name
Person.__count += 1
print Person.__count

p1 = Person('Bob')
p2 = Person('Alice')

try:
print Person.__count
except AttributeError:
print 'attributeerror'
class Person(object):
count = 0
def __init__(self,name):
self.name = name
Person.count+=1

p1 = Person('Bob')
print Person.count

p2 = Person('Alice')
print Person.count

p3 = Person('Tim')
print Person.count
class Person(object):
def __init__(self, name, score):
self.name = name
self.__score = score

p = Person('Bob', 59)

print p.name
try:
print p.__score
except AttributeError:
print 'attribute error'
class Person(object):
def __init__(self,name,gender,birth,**kw):
self.name=name
self.gender =gender
self.birth=birth
for k,v in kw.items():
setattr(self,k,v)

xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')

print xiaoming.name
class Person(object):
pass


p1 = Person()
p1.name = 'Bart'

p2 = Person()
p2.name = 'Adam'

p3 = Person()
p3.name = 'Lisa'

L1 = [p1, p2, p3]
L2 = sorted(L1,lambda a, b: cmp(a.name, b.name))

print(L2[0].name)
print(L2[1].name)
print(L2[2].name)
class Person:
pass

xiaoming = Person()
xiaohong = Person()

print xiaoming
print xiaohong
print xiaoming == xiaohong
from __future__ import unicode_literals

s = 'am I an unicode?'
print isinstance(s, unicode)
try:
import json
except ImportError:
from simplejson import json

print json.dumps({'python':2.7})
from os.path import isdir,isfile

print not isdir(r'/data/webroot/resource/python')
print not isfile(r'/data/webroot/resource/python/test.txt')
课程须知
本课程是Python入门的后续课程 1、掌握Python编程的基础知识 2、掌握Python函数的编写 3、对面向对象编程有所了解更佳
老师告诉你能学到什么?
1、什么是函数式编程 2、Python的函数式编程特点 3、Python的模块 4、Python面向对象编程 5、Python强大的定制类

微信扫码,参与3人拼团

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

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

本次提问将花费2个积分

你的积分不足,无法发表

为什么扣积分?

本次提问将花费2个积分

继续发表请点击 "确定"

为什么扣积分?

举报

0/150
提交
取消