class Student: def __init__(self,name,score): self.name = name self.score = score def say_score(self): print("{0}的分数是{1}".format(self.name,self.score)) s1 = Student("张三",80) print(s1.name,s1.score) s1.say_score() s2 = Student("李四",90) print(s2.name,s2.score)
import turtle a=input("请输入一个x:") b=input("请输入一个y:") c=input("请输入一个width:") d=input("请输入一个height:") class MyRectangle: def __init__(self,x,y,width,height): self.x=x self.y=y self.width=width self.height=height if self.x=="": self.x=0 if self.x!="": self.x=float(x) if self.y=="": self.y=0 if self.y!="": self.y=float(y) if self.width == "": self.width = 100 if self.width!="": self.width=float(width) if self.height == "": self.height = 100 if self.height!="": self.height=float(height) def getArea(self): return self.width*self.height def getPerimeter(self): return 2*(self.height+self.width) def draw(self): turtle.color("red") turtle.penup() turtle.goto(self.x,self.y) turtle.pendown() turtle.right(90) turtle.forward(self.width) turtle.right(90) turtle.forward(self.height) turtle.right(90) turtle.forward(self.width) turtle.right(90) turtle.forward(self.height) turtle.done m1=MyRectangle(a,b,c,d) print(m1.getArea()) print(m1.getPerimeter()) m1.draw()
老师,为什么我在调用draw方法的之后海龟作图不显示?
老师,我想问一下,字典不是无序的吗,那么序列解包得到的内容也是无序的,如果想获取指定值,那么序列解包不是没用了吗,我想知道序列解包在实际应用中有啥用啊,不是太理解,谢谢老师
为什么这两个地方没有按老师写的那样,结果仍然和老师的结果一样
num = 0 degree = 'ABCDE' #degree = ['A','B','C','D','E']也可以使用列表形式 score = int(input('请输入一个0--100之间的数:')) if score<0 or score>100: score = int(input('输入错误!!请重新输入一个0--100之间的数:')) else: num = score//10 if num <6:num=5 print('分数是:{0},等级是:{1}'.format(score,degree[num-9]))
if num <6:num=5,为何此处能直接赋值,前面不是说到条件选择结构中不能使用赋值运算符吗?
有些困惑?老师能否细说一下,谢谢!
a = a//2这是什么意思
#测试浅拷贝和深拷贝 import copy class MobilePhone: def __init__(self,cpu,screen): self.cpu=cpu self.screen=screen class Cpu: def calulate(self): print("算你个12345") print("cpu对象",self) class Screen: def show(self): print("显示一个好看的画面") print("screen:",self) #测试变量值 c1=Cpu() c2=c1 print(c1) print(c2) #测试浅复制 s1=Screen m1=MobilePhone(c1,s1) m2=copy.copy(m1) m1.cpu.calulate() print("*************************") print(m1.cpu) #print(m1,m1.cpu,m1.screen) #print(m2,m2.cpu,m2.screen)
老师 这个代码我还是不明白为什么给手机类传参传的是cpu类和screen类 第二个问题m1.cpu是不是就是指c1这个实例对象,所以m1.cpu.calulate就相当于c1.calulate 这样理解对吗
课程中讲到,键可以为整数,浮点数等任意不可变数据。为什么我用1,2,3,4作为键的时候,会报错?
Mysingleton: __obj = __init_flag = (*args**kwargs): .__obj == : .__obj = .() .__obj (name): Mysingleton.__init_flag: () .name = name Mysingleton.__init_flag = a = Mysingleton() b = Mysingleton() (a) (b)
init......
<__main__.Mysingleton object at 0x0000021586CE1FA0>
老师,运行结果出现的两个object地址是用new()创建的对象的地址吗
老师好,这个我是照着高淇老师的抄的,为什么出错了啊?
[y*2 for y in range(1,5)]
老师,我输入这个pycharm上面提示语句无效是为什么呀?
老师为什么del a[800]后两个300和400的id图一样,图二不一样啊
>>>a=“axt”
>>>print(a)
axt
>>>a
‘axt’
直接敲a输出 为什么和print(a)不一致
****************可迭代的含义是什么
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637