Sorted out the content of this article on Zhihu, quite feel interesting, share with you.

One line of code prints the multiplication table

print( ‘\n’ . join ([ ” . join ([ “%2sx%2s=%2s” %(j,i,i*j) for j in range ( 1 ,i+ 1 )]) for i in range ( 1 , 10 )]))

One line of code prints the maze

print ( ” .join(import( ‘random’ ).choice( ‘\u2571\u2572’ ) for i in range(50*24))) One line of code says love

Print (‘ \ n ‘. Join ([‘. Join ([(‘ Love ‘[(x-y) % len (‘ Love’)] the if ((0.05) x * * * 2 + 0.1) (y * * * 2-1) 3 – (0.05) x * * * * * 2 (y 0.1)** 3 = 0 else “) for x in range(-30, 30)]) for y in range(-30, -30, -1)])!

One line of code to print turtle turtle

print( ‘\n’ .join([ ” .join([ ” if abs(( lambda a: Lambda z, c, n, a (a to z, c, n)) (lambda s, z, c, n, z if n = = 0 else s (s, zz + c, c, n – 1)) (0, 0.02 to 0.05 j * * x + y, 40 )) 2 else ” for x in range( -80 , 20 )]) for y in range( -20 , 20 )]))

Isn’t it interesting that a line of Python code can do this?

For more python, add Q3044236899

Author: CSDN