I will post my answer, but am interested in a more elegant solutions concise but easily readable solution! (Would someone new-ish to python be able to understand it?)
这里有一个1-liner没有任何模块的解决方案:
>>> next((x for x in range(1000, 10000) if str(x*x)[-4:] == str(x)), None)
9376
如果您考虑来自的数字1000 to 3162,他们的平方给你一个7数字。所以迭代自3163将是一个更优化的,因为正方形应该是8数字一。感谢@adrin 提出了这么好的观点。
>>> next((x for x in range(3163, 10000) if str(x*x)[-4:] == str(x)), None)
9376