Quine é um programa que não recebe nenhuma entrada, mas gera uma cópia de seu próprio código. Nós discutimos quine em 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 (_%_)
Explicação: O código acima é um uso clássico de formatação de string. Primeiramente estamos definindo uma variável _ e atribuindo-lhe '_=%r;print _%%_'. Em segundo lugar, estamos imprimindo _%_ . Aqui estamos imprimindo _ com _ como entrada para formatação de string. Então %r in _ obtém o valor de _. Você pode até usar %s em vez de %r . Usamos o dobro % em '_=%r;print _%%_' para escapar % . 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 abrir() função para imprimir seu código-fonte.