Python有很多优雅有趣的代码写法,同时还很简短,那么一起来看看一行Python代码能做什么。
打印python之禅,这是‘人生苦短,我用python’的出处
输入代码:
import this
执行结果:
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
打印99乘法表
输入代码:
print('\n'.join([' '.join(['%s*%s=%-2s' % (y, x, x*y)for yin range(1, x+1)])for xin range(1, 10)]))
执行结果:
看漫画
输入代码:
import antigravity
执行结果:
画爱心
输入代码:
print('\n'.join([''.join([('**********'[(x-y)%10]if((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3<=0 else' ')for xin range(-30,30)])for yin range(15,-15,-1)]))
执行结果:
是不是很有趣,你还有那些一行代码就能实现又好玩的代码,欢迎留言分享
_______________END______________
网友评论