画四个矩形时,效果图会有箭头显示,如何去掉
a
=
'abc'
b
'xyz'
import
os
print
(os.path.join(a,b))
老师,以这个方式输出的结果显示abc\xyz,中间这条下划线怎么去掉?
老师
score1 = (()) grade = score1 < score > : score = (()) : score >= : grade = score >= : grade = score >= : grade = score >= : grade = : grade = (.format(scoregrade))
第四行代码执行完以后是否有逻辑错误,比如先输入101进入第四行代码,在输入任何数字,程序都会执行完成,不会再进入第三行进行判断
视频中的方法如果第一次输错分数第二次再输入的时候不会运行,这是我修改的代码,请老师看一下是否合理:
score = int(input('请输入分数: '))degree = 'ABCDE'while True: if score > 100 or score < 0: score = int(input('输入有误!请重新输入分数: ')) else: num = score // 10 if num < 6: num = 5 if num > 9: num = 9 print('分数为:{0},等级为:{1}'.format(score,degree[9-num])) break
嗯嗯,可是我还不太理解为啥就不能多写呢,是因为python3中继承算法C3的限值吗?要遵循优先级的原则,否则就报错?
class A: pass class B: pass class D(B,A): pass class C(A,B): pass class E(C,D): pass
问题:为何这个多重继承会报错呢?
已经明白了,老师,不用回了,谢谢老师,一个小bug我没发现到,少了个括号
class ComputerFactory: __obj = None __init_flag = True __countLenovo = 0 __countAsus = 0 __countHasee = 0 def __new__(cls, *args, **kwargs): #单例模式 if cls.__obj==None: cls.__obj = object.__new__(cls) return cls.__obj #new方法创建完成一定要返回我们的实例对象 def __init__(self): #单例模式 if ComputerFactory.__init_flag: print('构造初始化') ComputerFactory.__init_flag = False def produce(self,brand): #工厂模式 if brand =='联想': ComputerFactory.__countLenovo += 1 return Lenovo() elif brand == '华硕': ComputerFactory.__countAsus += 1 return Asus() elif brand == '神舟': ComputerFactory.__countHasee += 1 return Hasee() def calculate(self): a = [ComputerFactory.__countAsus,ComputerFactory.__countLenovo,ComputerFactory.__countHasee] print('本公司一共生产了{0}台电脑'.format(sum(a)) class Computer: __count = 0 def __init__(self): Computer.__count +=1 def calculate(self): print('生产了{0}台电脑'.format(Computer.__count)) class Lenovo(Computer): __num = 0 def __init__(self): # Computer.__init__(self) Lenovo.__num +=1 def calculate(self): print('共生产了{0}个联想电脑'.format(Lenovo.__num-1)) class Asus(Computer): __num = 0 def __init__(self): # Computer.__init__(self) Asus.__num += 1 def calculate(self): print('共生产了{0}个联想电脑'.format(Asus.__num-1)) class Hasee(Computer): __num = 0 def __init__(self): # Computer.__init__(self) Hasee.__num += 1 def calculate(self): print('共生产了{0}个联想电脑'.format(Hasee.__num-1)) t = ComputerFactory() h = Computer() t.produce('联想') h.calculate() Lenovo().calculate() t.calculate() Lenovo().calculate()
问题:不知道为啥会报这样的错,我反复核实没有格式的错误啊,求指导!老师
必须加grade储存吗?不加那个grade=“”会报错吗?
class Student: def __init__(self,name): self.name = name def __str__(self): return '名字是:',self.name p = Student('黄伟') print(p)
问题:为啥用,self.name就报错,而用字符格式化就可以?
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 Student: def __init__(self): print('这是构造函数') def __del__(self): print('销毁对象:{0}'.format(self)) p1 =Student() print(p1) P2 =Student() p3 =Student() del p3 print('程序结束')
问题:当程序结束后,Python解释器触发析构函数,p1和p2哪个最先被删除,他们的删除顺序是怎么确定的?
#使用 1 个函数代替上面的两个函数 def printName(isChinese,name,familyName): def inner_print(a,b): print("{0} {1}".format(a,b)) if isChinese: inner_print(familyName,name) else: inner_print(name,familyName) printName(True,"小七","高") printName(False,"George","Bush") 老师为啥打印printName(True,"小七","高")会是高小七
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637