Quine è un programma che non accetta input ma restituisce una copia del proprio codice. Abbiamo discusso 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 (_%_)
Spiegazione: Il codice sopra è un uso classico della formattazione delle stringhe. Innanzitutto stiamo definendo una variabile _ e assegnandolo '_=%r;print _%%_'. In secondo luogo stiamo stampando _%_ . Qui stiamo stampando _ con _ come input per la formattazione della stringa. COSÌ %R in _ ottiene il valore di _. Puoi anche usare %S invece di %R . Abbiamo usato il doppio % in '_=%r;print _%%_' per uscire % . 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 aprire() funzione per stampare il suo codice sorgente.