老师,\在行尾是续行符,为什么会报错,续行符到底该怎么用呢?
class Employee: id=0 def __init__(self,name,salary): self.name = name self.__salary = salary self.id = Employee.id+1000 Employee.id+=1 def __add__(self, other): if isinstance(other,Employee): return self.__salary+other.__salary else: return '不是同类不相加哦' def __str__(self): return 'Name:{0},salary:{1},id:{2}'.format(self.name,self.__salary,self.id) @property def salary(self): return self.__salary @salary.setter def salary(self,salary): if 1000<=salary<=50000: self.__salary = salary else: print('wrong!') p1 = Employee('A',1000000) p2 = Employee('B',12000) a=p1+p2 print(a) print(p1) print(p1.salary)
老师,这样输出的还是p1的1000000,没有起到限制范围的作用怎么办???
我给它斜杆了就不想给它换行,为什么会报错
def testcopy(): #测试浅拷贝 a = [10,20,[5,6]] b = copy.copy(a) print('a:',a) print('b:',b) print(id(a) is id(b)) print(id(a[0]) is id(b[0])) print(id(a[1]) is id(b[1])) print(id(a[2]),id(b[2])) b.append(30) b[2].append(7) print('*'*30) print('a:',a) print('b:',b) print(id(a[2])) print(id(b[2]))
老师,为什么id(a[1] ) == id(b[1]) 用is判断怎么是False
老师,这是这个视频后面的练习题。我没有做出来。那个写draw方法,不知道怎么写。
老师为什么我的python从桌面快捷方式打开是这个样子,我应该点击什么呀
python是解释型语言——什么是解释型语言?
字典是“”无序可变序列“”,既然是无序,在字典进行解包时,为什么有按顺序一一对应?如下:
>>> s = {'name':'gaoqi','age':18,'job':'programmer'} >>> a,b,c = s >>> a 'name' >>> b 'age' >>> c 'job'
老师,extend()函数是只能用于列表之间的添加吗??
country_counter = {} def addone(country): if country in country_counter: country_counter[country] += 1 else: country_counter[country] = 1 addone('China') addone('Japan') addone('china') print(len(country_counter))
老师,请问一下这个题目为什么打印出来会是3啊?加进去的元素不是应该在字典中,country in country_counter才会成立吗?
屏幕截图 2023-04-01 145333.png
这是啥情况
屏幕截图 2023-04-01 151240.png
这个b选项怎么解释啊
class Person: def work(self): print('你处于在职状态中') def play_game(self): print('{0}在打游戏'.format(self)) def work2(s): print('好好工作,努力赚钱,迎娶媳妇{0}'.format(s)) p = Person() Person.play =play_game p.play() Person.work = work2 p.work()
老师,这里的动态给类增加新的方法,可以理解为该方法是该类属性的方法,从属于play和work属性的。
#测试运算符的重载 class Person: def __init__(self,name): self.name=name def __add__(self,other): if isinstance(other,Person): return "{0}--{1}".format(self.name,other.name) else: return "不是同类,不能相加" def __mul__(self,other): if isinstance(other,int): return self.name*other else: return "不是同类,不能相乘" p1=Person('高琪') p2=Person("高希希") x=p1+p2 print(x) print(p1*3)
老师
if isinstance(other,Person):和if isinstance(other,int):这两句代码不明白。int是什么?
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637