shortest python quine?

后端 未结 10 1800
天涯浪人
天涯浪人 2020-12-23 19:55
_=\'_=%r;print _%%_\';print _%_

Is this the shortest possible python quine, or can it be done better? This one seems to improve on all the entrie

10条回答
  •  无人及你
    2020-12-23 20:26

    In a slightly non-literal approach, taking 'shortest' to mean short in terms of the number of statements as well as just the character count, I have one here that doesn't include any semicolons.

    print(lambda x:x+str((x,)))('print(lambda x:x+str((x,)))',)
    

    In my mind this contends, because it's all one function, whereas others are multiple. Does anyone have a shorter one like this?

    Edit: User flornquake made the following improvement (backticks for repr() to replace str() and shave off 6 characters):

    print(lambda x:x+`(x,)`)('print(lambda x:x+`(x,)`)',)
    

提交回复
热议问题