这个分类以后会经常更新一些基础面试题,加强自己的印象
1.代码中要修改不可变数据会出现什么问题? 抛出什么异常?
答:代码不会正常运行,会抛出typeError的异常
2, a=1,b=2,不用中间变量交换 a 和 b 的值?
答:a,b = b,a
3.print 调用 Python 中底层的什么方法?
答:print默认调用sys.stdout.write,即往控制台打印字符串
4.`下面这段代码的输出结果将是什么?请解释?
1.class Parent(object):
2 .x = 1
3.class Child1(Parent):
4. pass
5.class Child2(Parent):
6. pass
7.print Parent.x, Child1.x, Child2.x
8. Child1.x = 2
9.print parent.x, Child1.x, Child2.x
10. parent.x = 3
11.print Parent.x, Child1.x, Child2.x`
答:7 返回 1 1 1 继承父类的属性,X=1 所以返回111
9 返回 1 2 1 值改变了child1的值 指向了其他对象
11 3 2 3 更改了parent 指向新的值 3 child1在上面指向别的值了 所以不会改,