4 ms·
You can omit the leading 0 before the dot when writing float literals so just a '.1' or any other such sub-1 float literal with no leading 0 is technically a va
by FRex 9y ago
You can omit the leading 0 before the dot when writing float literals so just a '.1' or any other such sub-1 float literal with no leading 0 is technically a valid but useless line of code starting with a dot (you could use it instead of pass I guess..). I can't think of a real use of a line starting with a dot off the top of my head.
- bpicolo 9y agoIdentifiers can't start with a number, so this should still be unambiguous probably?
- FRex 9y agoSure, that's the only example of line starting with a dot (I think, I'm not super good at Python, just okay) so anything else that isn't a float should be fine.
- owl57 9y agoProbably nothing remotely resembling this belongs in anything remotely resembling production code, but: In [1]: class Foo: ...: def __rmul__(self, other): ...: print("%s foos!" % other) ...: In [2]: .42 * Foo() 0.42 foos!
- FRex 9y agoThat's very nice. I tried to go for such an example originally but I only tried __mul__ because I thought it's like in Lua where __mul gets used even if only the second operand has a custom one.