Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
找到了这个 quine 的例子:
s='s=%r;print(s%%s)';print(s%s)
我明白了%s并%r执行了strandrepr功能,正如这里所指出的那样,但是这部分到底意味着什么s%s以及 quine 是如何工作的?
%s
%r
str
repr
s%s
s被设定为:
s
's=%r;print(s%%s)'
因此,%r将完全替换为(保留单引号) ins%s和 final%%替换为 single %,给出:
%%
%
因此是奎因。
运算符x % y表示替换y格式字符串中的值x,与 C printf 相同。另请注意,说明%%符代表文字 % 符号,因此s%%s在格式字符串中将打印为 s%s,并且不会捕获字符串。
x % y
y
x
s%%s