程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

What crazy things can one line of Python special effects do

編輯:Python

One line of code What can be done ?

Don't think that one line of code is too little , Nothing can be done , The world is never short of wisdom , What is missing is the ability to do things .

One 、 Love expresses

  • Opposite sex with heartbeat ? Then take the initiative
  • Code
print('\n'.join([''.join([('autofelix520'[(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 x in range(-30,30)])for y in range(15,-15,-1)]))
  • result
 felix5aut felix5aut
utofelix5autofeli utofelix5autofeli
autofelix5autofelix5autofelix5autofelix5a
autofelix5autofelix5autofelix5autofelix5aut
autofelix5autofelix5autofelix5autofelix5autof
utofelix5autofelix5autofelix5autofelix5autofe
tofelix5autofelix5autofelix5autofelix5autofel
ofelix5autofelix5autofelix5autofelix5autofeli
felix5autofelix5autofelix5autofelix5autofelix
elix5autofelix5autofelix5autofelix5autofelix5
ix5autofelix5autofelix5autofelix5autofelix5
5autofelix5autofelix5autofelix5autofelix5
autofelix5autofelix5autofelix5autofelix5a
ofelix5autofelix5autofelix5autofelix5
elix5autofelix5autofelix5autofelix5
ix5autofelix5autofelix5autofelix5
autofelix5autofelix5autofelix
ofelix5autofelix5autofeli
lix5autofelix5autofel
autofelix5autof
felix5aut
x5a
a 

Two 、 Banana fan extinguishes fire

  • It's too hot in summer ? Put out the fire with a banana fan
  • Code
print('\n'.join([''.join(['*'if abs((lambda a:lambda z,c,n:a(a,z,c,n))(lambda s,z,c,n:z if n==0else s(s,z*z+c,c,n-1))(0,0.02*x+0.05j*y,40))<2 else' 'for x in range(-80,20)])for y in range(-20,20)]))
  • result
**
***********
************
*********
* * ************ * *
****** * *************************** *
*************************************** *****
*******************************************
*** ******************************************** *
**************************************************
*******************************************************
* * *****************************************************
**** ******* * *******************************************************
***************** *******************************************************
*********************** *********************************************************
*********************** ********************************************************
**** ********************************************************************************
*********************************************************************************************
**** ********************************************************************************
*********************** ********************************************************
*********************** *********************************************************
***************** *******************************************************
**** ******* * *******************************************************
* * *****************************************************
*******************************************************
**************************************************
*** ******************************************** *
*******************************************
*************************************** *****
****** * *************************** *
* * ************ * *
*********
************
***********
** 

3、 ... and 、 multiplication table

  • Mathematics starts with children , The child has something to do during the holiday
  • Code
print('\n'.join([' '.join(['%s*%s=%-2s' % (y, x, x*y) for y in range(1, x+1)]) for x in range(1, 10)]))
  • result
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81

Four 、 Sort

  • The data is chaotic ? Then make an order
  • Code
qs = lambda xs : ( (len(xs) <= 1 and [xs]) or [ qs( [x for x in xs[1:] if x < xs[0]] ) + [xs[0]] + qs( [x for x in xs[1:] if x >= xs[0]] ) ] )[0]
print(qs([1, 3, 2, 10, 8, 6]))
  • result
[1, 2, 3, 6, 8, 10]

5、 ... and 、 Read novels

  • Too much free time ? Then read a novel to kill time
  • Code
import antigravity
  • result
A line of code to read a novel

6、 ... and 、 Maze building

  • Children's holidays are too noisy ? Go through a maze
  • Code
print(''.join(__import__('random').choice('/\\') for i in range(50*24)))
  • result
/\\/\\\\/\/\//////\///\\\\\\\\/\/////\\\\\\\/\/\//
\/\\/////\/\\//\\/\\\\\\///\//\\\/\//\/\/////\\///
\\/\\\/\///\\///\\\\/\\//\\\\//\\\/\//\\/\/\\//\\/
/\\\/\\\/\/\///\\/\////////\\\/\/\\\\\/\\//\\\\///
\\//\/\/\\///\\\\\\//////\\///\//\//\//\//\\\/\\\\
/\\//\/\//\////\\/\/\\/\\//\//\/////\////\/\///////
\//\\/\\//\\/\\/\//\/\/\\\\/\/\///\////////////////
/\/\///\//\//\/\\\////\\\/\////\/\/\//\\\/\\\\\\///
/////\//\\//\\\\\\/\//\\///\///\\\/\\\\/////\////\\
/\///\/////\/\/\/\///\//////\\\\/\///\\\\///\\\/\//
\\\////\\\////\///\/\///\\/\\\//\/\/\\/\\/\//\//\\\
/\\/\///\\\\//\/////\\/\\\\/\/\\\\///\\//\//\/\///\
///\\\/\\\\\//\//\\/\/////\\/\/\\//\\\//\\//\/\//\/
\\//\/\/\\/\////\\\//\\\\////\\//\/\\\/\\\/\\//\\\\
///\/\\/\/\\//\//\\\/////////\\\/\///\///\\\/\\////
//\\///\\\///////\\\\/\\\\\//\/\////\\/\\//\\//\\/\
\\\\/\/\////////\\//\/\//////\/\/\\\\\\/\//\///\/\/
/\\\///\\\//\//////\\\\\//\\/\////\\\/\/\\\\/\/\//\
///\//\\\\\//\//\/\\/\\\/\\\\\/\/////\\\\/\\/\\///\
\/\//\/\\\/\//\\//\//\\/\/\\/\/\//\//\\\\/\\\/\//\/
//\\////\///\/\\\\///\/\\\/\\/\\///\//\\/\///\////\

7、 ... and 、 Print python zen

  • Life is too short , I use python
  • Code
import this
  • result
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!

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved