python 要掌握面向对象,你得会做这些题吗?

最后

Python崛起并且风靡,因为优点多、应用领域广、被大牛们认可。学习 Python 门槛很低,但它的晋级路线很多,通过它你能进入机器学习、数据挖掘、大数据,CS等更加高级的领域。Python可以做网络应用,可以做科学计算,数据分析,可以做网络爬虫,可以做机器学习、自然语言处理、可以写游戏、可以做桌面应用…Python可以做的很多,你需要学好基础,再选择明确的方向。这里给大家分享一份全套的 Python 学习资料,给那些想学习 Python 的小伙伴们一点帮助!

👉Python所有方向的学习路线👈

Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。

👉Python必备开发工具👈

工欲善其事必先利其器。学习Python常用的开发软件都在这里了,给大家节省了很多时间。

👉Python全套学习视频👈

我们在看视频学习的时候,不能光动眼动脑不动手,比较科学的学习方法是在理解之后运用它们,这时候练手项目就很适合了。

👉实战案例👈

学python就与学数学一样,是不能只看书不做题的,直接看步骤和答案会让人误以为自己全都掌握了,但是碰到生题的时候还是会一筹莫展。

因此在学习python的过程中一定要记得多动手写代码,教程只需要看一两遍即可。

👉大厂面试真题👈

我们学习Python必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有阿里大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

‘_People__age’: 18, ‘__dict__’: <attribute ‘__dict__’ of ‘People’ objects>,

‘__weakref__’: <attribute ‘__weakref__’ of ‘People’ objects>, ‘__doc__’: None}

print(p1._People__name,p1._People__age) # luffy 18"luffy"
__age = 18

p1 = People()

print(p1.__name, p1.__age)

报错:AttributeError: ‘People’ object has no attribute ‘__name’

print(p1.dict) #{}
print(People.dict)

{‘__module__’: ‘__main__’, ‘_People__name’: ‘luffy’,

‘_People__age’: 18, ‘__dict__’: <attribute ‘__dict__’ of ‘People’ objects>,

‘__weakref__’: <attribute ‘__weakref__’ of ‘People’ objects>, ‘__doc__’: None}

print(p1._People__name,p1._People__age) # luffy 18


 


10,示例2, 现有如下代码, 会输出什么:



class People(object):

def __init__(self):
print(“__init__”)

def __new__(cls, *args, **kwargs):
print(“__new__”)
return object.new(cls, *args, **kwargs)

People() People(object):

def __init__(self):
print(“__init__”)

def __new__(cls, *args, **kwargs):
print(“__new__”)
return object.new(cls, *args, **kwargs)

People()


 



结果:__new__

__init__

__init__


 


11,请简单解释Python中 staticmethod(静态方法)和 classmethod(类方法), 并分别补充代码执行下列方法。


静态方法:非绑定方法,类和对象都可以调用


类方法:绑定给类的方法啊,类调用



class A(object):

def foo(self, x):
print(“executing foo(%s, %s)” % (self,x))

@classmethod
def class_foo(cls, x):
print(“executing class_foo(%s, %s)” % (cls,x))

@staticmethod
def static_foo(x):
print(“executing static_foo(%s)” % (x))

a = A() A(object):

def foo(self, x):
print(“executing foo(%s, %s)” % (self,x))

@classmethod
def class_foo(cls, x):
print(“executing class_foo(%s, %s)” % (cls,x))

@staticmethod
def static_foo(x):
print(“executing static_foo(%s)” % (x))

a = A()



class A(object):
def __init__(self,name):
self.name=name

**def** **foo**(self, x):
    print("executing foo(%s, %s)" % (self,x))

@classmethod
def class_foo(cls, x):
print(“executing class_foo(%s, %s)” % (cls,x))

@staticmethod
def static_foo(x):
print(“executing static_foo(%s)” % (x))

a = A(‘alice’)

a.foo(‘alice’)

A.class_foo(‘alice’)

a.static_foo(‘alice’)

A.static_foo(‘alice’)

‘’’
executing foo(<__main__.A object at 0x000002A5FED12AC8>, alice)
executing class_foo(<class ‘__main__.A’>, alice)
executing static_foo(alice)
executing static_foo(alice)
‘’’ A(object):
def __init__(self,name):
self.name=name

**def** **foo**(self, x):
    print("executing foo(%s, %s)" % (self,x))

@classmethod
def class_foo(cls, x):
print(“executing class_foo(%s, %s)” % (cls,x))

@staticmethod
def static_foo(x):
print(“executing static_foo(%s)” % (x))

a = A(‘alice’)

a.foo(‘alice’)

A.class_foo(‘alice’)

a.static_foo(‘alice’)

A.static_foo(‘alice’)

‘’’
executing foo(<__main__.A object at 0x000002A5FED12AC8>, alice)
executing class_foo(<class ‘__main__.A’>, alice)
executing static_foo(alice)
executing static_foo(alice)
‘’’


 


12,请执行以下代码,解释错误原因,并修正错误。


错误原因:@property可以将函数属性转化为数据属性



class Dog(object):

def __init__(self,name):
self.name = name

@property
def eat(self):
print(" %s is eating" %self.name)

d = Dog(“ChenRonghua”)
d.eat() Dog(object):

def __init__(self,name):
self.name = name

@property
def eat(self):
print(" %s is eating" %self.name)

d = Dog(“ChenRonghua”)
d.eat()


报错内容:



Traceback (most recent call last):
File “D:/py.py”, line 27, in <module>
d.eat()
TypeError: ‘NoneType’ object is not callablecall last):
File “D:/py.py”, line 27, in <module>
d.eat()
TypeError: ‘NoneType’ object is not callable


改正如下:



class Dog(object):

def __init__(self,name):
self.name = name

@property
def eat(self):
print(" %s is eating" %self.name)

d = Dog(“ChenRonghua”)
d.eat Dog(object):

def __init__(self,name):
self.name = name

@property
def eat(self):
print(" %s is eating" %self.name)

d = Dog(“ChenRonghua”)
d.eat


因为有了property,用户就可以直接输入得到结果,对于使用者来说,感知不到其属性,这就是使用property的方便之处,此方法必须有一个返回值。return 或者print都可以。


为什么要用property?


一个类的函数定义成特性以后,对象再去使用的时候obj.name,根本无法察觉自己的name是执行了一个函数然后计算出来的,这种特性的使用方式 遵循了统一访问的原则


13,下面这段代码的输出结果将是什么?请解释。



class Parent(object):
x = 1

class Child1(Parent):
pass

class Child2(Parent):
pass

print(Parent.x, Child1.x, Child2.x)
Child1.x = 2
print(Parent.x, Child1.x, Child2.x)
Parent.x = 3
print(Parent.x, Child1.x, Child2.x)

1 1 1 继承自父类的类属性x,所以都一样,指向同一块内存地址

1 2 1 更改Child1,Child1的x指向了新的内存地址

3 2 3 更改Parent,Parent的x指向了新的内存地址


 


14,多重继承的执行顺序,请解答以下输出结果是什么?并解释。



super()表示的是 子类的mro()列表中的下一个
print(G.mro())
[<class ‘__main__.G’>, <class ‘__main__.D’>, <class ‘__main__.A’>, <class ‘__main__.B’>, <class ‘object’>]
print(F.mro())
<class ‘__main__.F’>, <class ‘__main__.C’>, <class ‘__main__.B’>, <class ‘__main__.D’>, <class ‘__main__.A’>, <class ‘object’>表示的是 子类的mro()列表中的下一个
print(G.mro())
[<class ‘__main__.G’>, <class ‘__main__.D’>, <class ‘__main__.A’>, <class ‘__main__.B’>, <class ‘object’>]
print(F.mro())
[<class ‘__main__.F’>, <class ‘__main__.C’>, <class ‘__main__.B’>, <class ‘__main__.D’>, <class ‘__main__.A’>, <class ‘object’>]


 



class A(object):
def __init__(self):
print(‘A’)
super(A, self).init()

class B(object):
def __init__(self):
print(‘B’)
super(B, self).init()

class C(A):
def __init__(self):
print(‘C’)
super(C, self).init()

class D(A):
def __init__(self):
print(‘D’)
super(D, self).init()

class E(B, C):
def __init__(self):
print(‘E’)
super(E, self).init()

class F(C, B, D):
def __init__(self):
print(‘F’)
super(F, self).init()

class G(D, B):
def __init__(self):
print(‘G’)
super(G, self).init()

if name == ‘__main__’:
g = G()
f = F()

G

D

A

B

F

C

B

D

A A(object):

def __init__(self):
print(‘A’)
super(A, self).init()

class B(object):
def __init__(self):
print(‘B’)
super(B, self).init()

class C(A):
def __init__(self):
print(‘C’)
super(C, self).init()

class D(A):
def __init__(self):
print(‘D’)
super(D, self).init()

class E(B, C):
def __init__(self):
print(‘E’)
super(E, self).init()

class F(C, B, D):
def __init__(self):
print(‘F’)
super(F, self).init()

class G(D, B):
def __init__(self):
print(‘G’)
super(G, self).init()

if name == ‘__main__’:
g = G()
f = F()

G

D

A

B

F

C

B

D

A


 


15,请编写一段符合多态特性的代码.



class Animal:
def __init__(self, name):
self.name = name

class People(Animal):
def talk(self):
print(‘%s is talking’ % self.name)

class Dog(Animal):
def talk(self):
print(‘%s is talking’ % self.name)

def func(animal):
animal.talk()

p=People(‘alice’)

d=Dog(‘wang’)

func§

func(d)

‘’’
alice is talking
wang is talking
‘’’ Animal:
def __init__(self, name):
self.name = name

class People(Animal):
def talk(self):
print(‘%s is talking’ % self.name)

class Dog(Animal):
def talk(self):
print(‘%s is talking’ % self.name)

def func(animal):
animal.talk()

p=People(‘alice’)

d=Dog(‘wang’)

func§

func(d)

‘’’
alice is talking
wang is talking
‘’’


 


16,很多同学都是学会了面向对象的语法,却依然写不出面向对象的程序,原因是什么呢?原因就是因为你还没掌握一门面向对象设计利器,即领域建模,请解释下什么是领域建模,以及如何通过其设计面向对象的程序? <http://www.cnblogs.com/alex3714/articles/5188179.html> 此blog最后面有详解



领域模型,顾名思义,就是需求所涉及的领域的一个建模,更通俗的讲法是业务模型。
定义:
需求到面向对象的桥梁
作用:
1.发掘重要的业务领域概念
2.建立业务领域概念之间的关系
方法:
从用例中找名词
领域建模的三字经方法:找名词、加属性、连关系。
参考:http://www.cnblogs.com/linhaifeng/articles/6182264.html#_label15
http://www.cnblogs.com/linhaifeng/articles/7341318.html1.发掘重要的业务领域概念
2.建立业务领域概念之间的关系
方法:
从用例中找名词
领域建模的三字经方法:找名词、加属性、连关系。
参考:http://www.cnblogs.com/linhaifeng/articles/6182264.html#_label15
http://www.cnblogs.com/linhaifeng/articles/7341318.html


 


17,请写一个小游戏,人狗大站,2个角色,人和狗,游戏开始后,生成2个人,3条狗,互相混战,人被狗咬了会掉血,狗被人打了也掉血,狗和人的攻击力,具备的功能都不一样。注意,请按题14领域建模的方式来设计类。



class Animal:
def __init__(self, name,life_value,aggressivity):
self.name = name
self.life_value = life_value
self.aggressivity = aggressivity

**def** **attack**(self,enemy):
    enemy.life_value -= self.aggressivity

class People(Animal):
camp=‘home’
def attack(self,enemy):
super().attack(enemy)
print(‘from people’)

class Dog(Animal):
camp=‘wo’
def attack(self,enemy):
super().attack(enemy)
print(‘from dog’)

p1=People(‘alice’,80,30)
p1=People(‘alex’,80,30)
d1=Dog(‘w1’,90,50)
d2=Dog(‘w2’,90,50)
d3=Dog(‘w3’,90,50)

print(p1.life_value)

d1.attack(p1)

print(p1.life_value)

print(d1.life_value)

p1.attack(d1)

print(d1.life_value) Animal:

**def** **\_\_init\_\_**(self, name,life_value,aggressivity):
    self.name = name
    self.life_value = life_value
    self.aggressivity = aggressivity

**def** **attack**(self,enemy):
    enemy.life_value -= self.aggressivity

class People(Animal):
camp=‘home’
def attack(self,enemy):
super().attack(enemy)
print(‘from people’)

class Dog(Animal):
camp=‘wo’
def attack(self,enemy):
super().attack(enemy)
print(‘from dog’)

p1=People(‘alice’,80,30)
p1=People(‘alex’,80,30)
d1=Dog(‘w1’,90,50)
d2=Dog(‘w2’,90,50)
d3=Dog(‘w3’,90,50)

print(p1.life_value)

d1.attack(p1)

print(p1.life_value)

print(d1.life_value)

p1.attack(d1)

print(d1.life_value)


 


18,编写程序, 在元类中控制把自定义类的数据属性都变成大写.


19,编写程序, 在元类中控制自定义的类无需init方法.



class Mymeta(type):
def __new__(cls,class_name,class_bases,class_dic):
update_dic = {}
for i in class_dic:
if not callable(class_dic[i]) and not i.startswith(‘__’):
update_dic[i.upper()]=class_dic[i]
else:
update_dic[i]=class_dic[i]
return type.new(cls,class_name,class_bases,update_dic)

**def** **\_\_call\_\_**(self, *args, **kwargs):
    obj=object.__new__(self)
    **if** args:
        **raise** TypeError('must be keyword argument')
    **for** i **in** kwargs:
        obj.__dict__[i]=kwargs[i]
    **return** obj

class Chinese(metaclass=Mymeta):
country=‘china’
tag=‘legend of the dragon’

**def** **talk**(self):
    print('%s is talking'%self.name)

print(Chinese.__dict__)

ch=Chinese(name=‘alice’,age=18)

ch.talk()

print(ch.__dict__) Mymeta(type):

**def** **\_\_new\_\_**(cls,class_name,class_bases,class_dic):
    update_dic = {}
    **for** i **in** class_dic:
        **if** **not** callable(class_dic[i]) **and** **not** i.startswith('\_\_'):
            update_dic[i.upper()]=class_dic[i]
        **else**:
            update_dic[i]=class_dic[i]
    **return** type.__new__(cls,class_name,class_bases,update_dic)

**def** **\_\_call\_\_**(self, *args, **kwargs):
    obj=object.__new__(self)
    **if** args:
        **raise** TypeError('must be keyword argument')
    **for** i **in** kwargs:
        obj.__dict__[i]=kwargs[i]
    **return** obj

class Chinese(metaclass=Mymeta):
country=‘china’
tag=‘legend of the dragon’

**def** **talk**(self):
    print('%s is talking'%self.name)

print(Chinese.__dict__)

ch=Chinese(name=‘alice’,age=18)

ch.talk()

print(ch.__dict__)


 


20,编写程序, 编写一个学生类, 要求有一个计数器的属性, 统计总共实例化了多少个学生.



class Student:
__count = 0
def __init__(self, name, age):
self.name = name
self.age = age
Student.__count += 1

@property
def talk(self):
print(‘%s is talking’ % self.name)

@staticmethod
def tell_count():
print(‘总共实例化了 %s 人’ % Student.__count)

s1 = Student(‘alice’, 18)

s2 = Student(‘alex’, 20)

s3 = Student(‘egon’, 28)

Student.tell_count()

s1.tell_count()

s1.talk

s2.talk Student:

__count = 0
**def** **\_\_init\_\_**(self, name, age):
    self.name = name
    self.age = age
    Student.__count += 1

@property
def talk(self):
print(‘%s is talking’ % self.name)

@staticmethod
def tell_count():
print(‘总共实例化了 %s 人’ % Student.__count)

s1 = Student(‘alice’, 18)

s2 = Student(‘alex’, 20)

s3 = Student(‘egon’, 28)

Student.tell_count()

s1.tell_count()

s1.talk

s2.talk


结果:



结果:

1

{‘name’: ‘james’, ‘sex’: ‘male’, ‘age’: 32}

2

{‘name’: ‘enbede’, ‘sex’: ‘male’, ‘age’: 23}

2

{‘__module__’: ‘__main__’, ‘_count’: 2, ‘__init__’: <function Student.init at 0x00000190B1B959D8>, ‘learn’: <property object at 0x00000190B19047C8>, ‘tell_count’: <staticmethod object at 0x00000190B1B9CAC8>, ‘__dict__’: <attribute ‘__dict__’ of ‘Student’ objects>, ‘__weakref__’: <attribute ‘__weakref__’ of ‘Student’ objects>, ‘__doc__’: None}

总共实例化了:2

james is learning1

{‘name’: ‘james’, ‘sex’: ‘male’, ‘age’: 32}

2

{‘name’: ‘enbede’, ‘sex’: ‘male’, ‘age’: 23}

2

{‘__module__’: ‘__main__’, ‘_count’: 2, ‘__init__’: <function Student.init at 0x00000190B1B959D8>, ‘learn’: <property object at 0x00000190B19047C8>, ‘tell_count’: <staticmethod object at 0x00000190B1B9CAC8>, ‘__dict__’: <attribute ‘__dict__’ of ‘Student’ objects>, ‘__weakref__’: <attribute ‘__weakref__’ of ‘Student’ objects>, ‘__doc__’: None}

总共实例化了:2

james is learning


 



_*_ coding: utf-8 _*_

‘’’
练习1:编写一个学生类,产生一堆学生对象, (5分钟)
要求:
有一个计数器(属性),统计总共实例了多少个对象
‘’’
class Student:
count = 0
def __init__(self,name,sex,age):
self.name = name
self.sex = sex
self.age = age
Student.count +=1

**def** **learn**(self):
    print("%s is learning"%self.name)

stu1 = Student(‘james’,‘male’,32)
print(stu1.count)
print(stu1.dict)
stu2 = Student(‘enbede’,‘male’,23)
print(stu2.count)
print(stu2.dict)
print(Student.count)
print(Student.dict)

结果:

1

{‘name’: ‘james’, ‘sex’: ‘male’, ‘age’: 32}

2

{‘name’: ‘enbede’, ‘sex’: ‘male’, ‘age’: 23}

2

{‘__module__’: ‘__main__’, ‘count’: 2, ‘__init__’: <function Student.__init__ at 0x000001E5DA9759D8>, ‘learn’: <function Student.learn at 0x000001E5DA975A60>, ‘__dict__’: <attribute ‘__dict__’ of ‘Student’ objects>, ‘__weakref__’: <attribute ‘__weakref__’ of ‘Student’ objects>, ‘__doc__’: None}

Process finished with exit code 0

‘’’
练习1:编写一个学生类,产生一堆学生对象, (5分钟)
要求:
有一个计数器(属性),统计总共实例了多少个对象
‘’’
class Student:
count = 0
def __init__(self,name,sex,age):
self.name = name
self.sex = sex
self.age = age
Student.count +=1

**def** **learn**(self):
    print("%s is learning"%self.name)

stu1 = Student(‘james’,‘male’,32)
print(stu1.count)
print(stu1.dict)
stu2 = Student(‘enbede’,‘male’,23)
print(stu2.count)
print(stu2.dict)
print(Student.count)
print(Student.dict)

结果:

1

{‘name’: ‘james’, ‘sex’: ‘male’, ‘age’: 32}

2

{‘name’: ‘enbede’, ‘sex’: ‘male’, ‘age’: 23}

2

{‘__module__’: ‘__main__’, ‘count’: 2, ‘__init__’: <function Student.__init__ at 0x000001E5DA9759D8>, ‘learn’: <function Student.learn at 0x000001E5DA975A60>, ‘__dict__’: <attribute ‘__dict__’ of ‘Student’ objects>, ‘__weakref__’: <attribute ‘__weakref__’ of ‘Student’ objects>, ‘__doc__’: None}

Process finished with exit code 0


 


21,编写程序, A 继承了 B, 俩个类都实现了 handle 方法, 在 A 中的 handle 方法中调用 B 的 handle 方法



class B:
def handle(self):
print(‘from B handle’)

class A(B):
def handle(self):
super().handle()
# print(‘from A handle’)

a=A()

a.handle() B:

**def** **handle**(self):
    print('from B handle')

class A(B):
def handle(self):
super().handle()
# print(‘from A handle’)

a=A()

a.handle()


 


22,编写程序, 如下有三点要求:


1. 自定义用户信息数据结构, 写入文件, 然后读取出内容, 利用json模块进行数据的序列化和反序列化
2. 定义用户类,定义方法db,例如 执行obj.db可以拿到用户数据结构
3. 在该类中实现登录、退出方法, 登录成功将状态(status)修改为True, 退出将状态修改为False(退出要判断是否处于登录状态).密码输入错误三次将设置锁定时间(下次登录如果和当前时间比较大于10秒即不允许登录)



import json
import time
class User:
def __init__(self, name, password):
self.name = name
self.password = password
self.status = False
self.timeout = 0

@property
def db(self):
with open(self.name+‘.txt’, ‘r’, encoding=‘utf-8’) as f:
data = json.load(f)
return data

**def** **save**(self):
    obj={}
    obj[self.name]={'password':self.password,'status':self.status,'timeout':self.timeout}
    **with** open(self.name+'.txt', 'w', encoding='utf-8') **as** f:
        json.dump(obj,f)

**def** **login**(self):
    **with** open(self.name+'.txt', 'r+', encoding='utf-8') **as** f:
        data = json.load(f)
        count = 0
        **while** count < 3:
            password = input('password>>:').strip()
            **if** password != data[self.name]['password']:
                count += 1
                **continue**
            **else**:
                **if** data[self.name]['timeout'] != 0:
                    **if** time.time() - data[self.name]['timeout'] > 10:
                        print('不允许登录了!超时')
                        **break**
                    **else**:
                        data[self.name]['status'] = **True**
                        f.seek(0)
                        f.truncate()
                        json.dump(data, f)
                        print('----welcome----')
                        **break**
                **else**:
                    data[self.name]['status'] = **True**
                    f.seek(0)
                    f.truncate()
                    json.dump(data, f)
                    print('----welcome----')
                    **break**

        **else**:
            data[self.name]['timeout']=time.time()
            f.seek(0)
            f.truncate()
            json.dump(data,f)


**def** **quit**(self):
    **with** open(self.name+'.txt', 'r+', encoding='utf-8') **as** f:
        data = json.load(f)
        **if** data[self.name]['status'] == **True**:
            data[self.name]['status'] = **False**
            f.seek(0)
            f.truncate()
            json.dump(data, f)
        **else**:
            print('您是退出状态!')

alex=User(‘alex’,‘123’)

egon=User(‘egon’,‘456’)

# alex.save()

# egon.save()

# print(alex.db)

# print(egon.db)

# alex.login()

alex.quit()

# egon.quit()

print(alex.db)

print(egon.db)

alex.login()

egon.login() json

import time
class User:
def __init__(self, name, password):
self.name = name
self.password = password
self.status = False
self.timeout = 0

@property
def db(self):
with open(self.name+‘.txt’, ‘r’, encoding=‘utf-8’) as f:
data = json.load(f)
return data

**def** **save**(self):
    obj={}
    obj[self.name]={'password':self.password,'status':self.status,'timeout':self.timeout}
    **with** open(self.name+'.txt', 'w', encoding='utf-8') **as** f:
        json.dump(obj,f)

**def** **login**(self):
    **with** open(self.name+'.txt', 'r+', encoding='utf-8') **as** f:
        data = json.load(f)
        count = 0
        **while** count < 3:
            password = input('password>>:').strip()
            **if** password != data[self.name]['password']:
                count += 1
                **continue**
            **else**:
                **if** data[self.name]['timeout'] != 0:
                    **if** time.time() - data[self.name]['timeout'] > 10:
                        print('不允许登录了!超时')
                        **break**
                    **else**:
                        data[self.name]['status'] = **True**
                        f.seek(0)
                        f.truncate()
                        json.dump(data, f)
                        print('----welcome----')
                        **break**
                **else**:
                    data[self.name]['status'] = **True**
                    f.seek(0)
                    f.truncate()
                    json.dump(data, f)
                    print('----welcome----')
                    **break**

        **else**:
            data[self.name]['timeout']=time.time()
            f.seek(0)
            f.truncate()
            json.dump(data,f)


**def** **quit**(self):
    **with** open(self.name+'.txt', 'r+', encoding='utf-8') **as** f:
        data = json.load(f)
        **if** data[self.name]['status'] == **True**:
            data[self.name]['status'] = **False**
            f.seek(0)
            f.truncate()
            json.dump(data, f)
        **else**:
            print('您是退出状态!')

alex=User(‘alex’,‘123’)

egon=User(‘egon’,‘456’)

# alex.save()

# egon.save()

# print(alex.db)

# print(egon.db)

# alex.login()

alex.quit()

# egon.quit()

print(alex.db)

print(egon.db)

alex.login()

egon.login()


 


23,用面向对象的形式编写一个老师角色, 并实现以下功能, 获取老师列表, 创建老师、删除老师、创建成功之后通过 pickle 序列化保存到文件里,并在下一次重启程序时能读取到创建的老师, 例如程序目录结构如下.



一、Python所有方向的学习路线

Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照下面的知识点去找对应的学习资源,保证自己学得较为全面。

img
img

二、Python必备开发工具

工具都帮大家整理好了,安装就可直接上手!img

三、最新Python学习笔记

当我学到一定基础,有自己的理解能力的时候,会去阅读一些前辈整理的书籍或者手写的笔记资料,这些笔记详细记载了他们对一些技术点的理解,这些理解是比较独到,可以学到不一样的思路。

img

四、Python视频合集

观看全面零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。

img

五、实战案例

纸上得来终觉浅,要学会跟着视频一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。img

六、面试宝典

在这里插入图片描述

在这里插入图片描述

简历模板在这里插入图片描述

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 13
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值