logo

Python의 Quine

콰인 입력을 받지 않지만 자체 코드의 복사본을 출력하는 프로그램입니다. 우리는 논의했습니다 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;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 열려 있는() 소스코드를 출력하는 기능입니다.