Quine ist ein Programm, das keine Eingaben entgegennimmt, sondern eine Kopie seines eigenen Codes ausgibt. Wir haben diskutiert Quine in 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 (_%_)
Erläuterung: Der obige Code ist eine klassische Verwendung der Zeichenfolgenformatierung. Zuerst definieren wir eine Variable _ und ihm „_=%r;print _%%_“ zuweisen. Zweitens drucken wir _%_ . Hier drucken wir _ mit _ als Eingabe für die String-Formatierung. Also %R in _ erhält den Wert von _. Sie können es sogar verwenden %S anstatt %R . Wir haben das Doppelte verwendet % in '_=%r;print _%%_' zum Entkommen % . 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 offen() Funktion zum Ausdrucken des Quellcodes.