Ken Thompson 的经典 C 程序
我尝试用Python来完成这个复制自己的程序,出乎预料,我最短只用了两行就完成了,可见Python的强大。解法一:
a = "print 'a = ', repr(a), '\n', repr(a)[1:-5]', a"
print 'a = ', repr(a), '\n', repr(a)[1:-5]
print 'a = ', repr(a), '\n', repr(a)[1:-5]
输出结果:
a = "print 'a = ', repr(a), '\n', repr(a)[1:-5]', a"
print 'a = ', repr(a), '\n', repr(a)[1:-5]
解法二:
a = ["print 'a = ', a, '\\n', ''.join(a)"]
print 'a = ', a, '\n', ''.join(a)
输出结果:print 'a = ', a, '\n', ''.join(a)
a = ["print 'a = ', a, '\\n', ''.join(a)"]
print 'a = ', a, '\n', ''.join(a)
有兴趣的朋友可以用C#试试~~
最后,真心祝愿震区的朋友平安。让我们坚信:中国人民是不可战胜的!