a,b = b,a 换值问题

a = "hello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello world"
b = "hello dearhello dearhello dearhello dearhello dearhello dearhello dearhello dearhello dearhello dearhello dearhello dearhello dearhello dearhello dearhello dearhello dearhello dearhello dear" print id(a),id(b)
print a
print b
a,b = b,a
print a
print b
print id(a),id(b)

整个操作其实是先进行右边,生成一个元组(b,a) 然后再将该元组 解包,分别赋值给左边的 a,b,实现达到交换值的目的

上一篇:php+C#.net混合开发


下一篇:react项目中页面跳转、刷新及获取网络状态