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是什么?
>>> a=[1,2,3,4] >>> a.delete(2,30) Traceback (most recent call last): File "<pyshell#39>", line 1, in <module> a.delete(2,30) AttributeError: 'list' object has no attribute 'delete' >>> a.delete(2,3) Traceback (most recent call last): File "<pyshell#40>", line 1, in <module> a.delete(2,3) AttributeError: 'list' object has no attribute 'delete'
老师,del()怎么使用呢,怎么删除元素呢。
老师,制表符有什么用,我用空格不也行吗?
print(type(str)) print(type(dict)) print(type(int)) print(type(list)) print(type(tuple)) print(type(set)) def test(): pass class Person(): def run(self): pass a = Person() c = a.run print(type(test)) print(type(c)) print(type(function)) print(type(method))
二、运行结果
三、疑问
老师你好,请问6个基本数据类型的模具类是type .python中一切都是对象,type 类实例化了所类,所有类继承与object类,用type方法 查看方法和函数的类型却报错了,他们不是type类的实例吗,
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637