在问这个问题时,我意识到我对原始字符串知之甚少.对于那些自称是Django训练师的人来说,这很糟糕.
我知道编码是什么,而且我知道u''自从我得到什么是Unicode以来我们独自做了什么.
但到底r''做了什么呢?它会产生什么样的字符串?
And above all, what the heck does ur'' do?
Finally, is there any reliable way to go back from a Unicode string to a simple raw string?
Ah, and by the way, if your system and your text editor charset are set to UTF-8, does u'' actually do anything?
关于在Python源代码中放置注释的"标准"方法:
def func():
"Func doc"
... <code>
'TODO: fix this'
#badFunc()
... <more code>
def func():
"Func doc"
... <code>
#TODO: fix this
#badFunc()
... <more code>
Run Code Online (Sandbox Code Playgroud)
我更喜欢将一般注释写为字符串而不是前缀#的.官方的Python风格指南没有提到使用字符串作为注释(如果我在阅读时没有错过它).
我喜欢这种方式主要是因为我认为这个#角色看起来很丑陋.据我所知,这些字符串不做任何事情.
这样做有缺点吗?