クワイン は入力を受け取らず、自身のコードのコピーを出力するプログラムです。私たちは議論しました C のクワイン . The shortest possible quine in python is just a single line of code! Python _='_=%r;print _%%_';print _%_
In case of Python3.x Python _='_=%r;print (_%%_)';print (_%_)
説明: 上記のコードは、文字列フォーマットの古典的な使用法です。まず変数を定義しています _ そしてそれに「_=%r;print _%%_」を割り当てます。次に、印刷を行っています _%_ 。ここでは、文字列フォーマットへの入力として _ を _ とともに出力しています。それで %r in _ は _ の値を取得します。使用することもできます %s の代わりに %r 。ダブルで使用しました % '_=%r;print _%%_' でエスケープします % . But you may say that the below code is the smallest right! Python print open(__file__).read()
You need to note that it is indeed the smallest python program that can print its own source code but it is not a quine because a quine should not use 開ける() ソースコードを出力する関数。