题目:Python 中交换两个变量的值是怎么实现的?为什么可以这样实现?
答案要点:
a,b = b,a
class People(object):
def __init__(self):
print('enter init')
p1 = People()
p2 = People() * 10
"""
输出结果:
enter init
enter init
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-32e88bb718e7> in <module>()
4
5 p1 = People()
----> 6 p2 = People() * 10
TypeError: unsupported operand type(s) for *: 'People' and 'int'
从结果可以看出是先进行实例化对象,再进行赋值的
"""
愿关注我们的人都能找到
属于自己的皮球