Is there a meaningless character in python that I could use as a marker in source?
基本上,我想要一个将被编译器完全忽略的ASCII字符。 不喜欢#,因为我之后的代码就行了,我只需要它清楚地标记某些东西。
我试图在Python中编写真正的长方程(Trig,复杂形状的表面区域等),我希望能够以不同的方式标记某些括号。 例如:
1 | slantHeight = (?(math.sqrt(?((baseSideLength/2) * (baseSideLength/2)) + heightSquared)?)` |
(问号应该代表所谓的神秘符号)
我想在一行中完成所有这些以保持文件大小。 我知道我可以这样做,我目前正在这样做。
1 2 3 4 5 6 | halfBaseSideLength = (.5 * baseSideLength) halfBaseSideLengthSquared = (halfBaseSideLength * halfBaseSideLength) baseSideLengthSquared = (baseSideLength * baseSideLength) heightSquared = (height * height) slantHeight = (math.sqrt(halfBaseSideLengthSquared + heightSquared)) |
但是,这太大了,特别是当你有这样的二十多个街区时。 所以我再问一遍:Python解释器是否有任何无意义的符号完全忽略了?
你可以这样做:
1 2 3 4 5 6 7 | slantHeight = math.sqrt( ( # halfBaseSideLengthSquared ( # halfBaseSideLength baseSideLength / 2) * (baseSideLength / 2)) + ( # heightSquared height * height)) |
或这个:
1 2 3 4 | def _(name, x): return x slantHeight = math.sqrt(_('halfBaseSideLengthSquared', _('halfBaseSideLength', baseSideLength / 2) * (baseSideLength / 2)) + _('heightSquared', height * height)) |
您甚至可以删除
我建议你不要再担心文件大小,而要注重可读性。 额外的线条不会受到伤害。 像这样的东西:
1 2 | halfBaseSideLength = (.5 * baseSideLength) halfBaseSideLengthSquared = (halfBaseSideLength * halfBaseSideLength) |
是有用的,因为它减少了重复,虽然更好的事情是:
1 | halfBaseSideLengthSquared = (.5 * baseSideLength) ** 2 |
显然,