Quine je program, ktorý neberie žiadny vstup, ale vydáva kópiu svojho vlastného kódu. Diskutovali sme quine v 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 (_%_)
Vysvetlenie: Vyššie uvedený kód je klasickým použitím formátovania reťazcov. Najprv definujeme premennú _ a jeho priradením '_=%r;print _%%_'. Po druhé, tlačíme _%_ . Tu tlačíme _ s _ ako vstup pre formátovanie reťazca. Takže %r v _ získa hodnotu _. Môžete dokonca použiť %s namiesto toho %r . Použili sme dvojité % v '_=%r;vytlačte _%%_' pre únik % . 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 OTVORENÉ() funkcia na vytlačenie jeho zdrojového kódu.