jero98772
(Jero98772)
July 15, 2025, 8:26pm
28
What on earth makes you think that? Is it this stuff?
That’s the regular expression to verify that a number is a float.
A string is not a float — before being converted to a float, it needs to be validated and typed. This is done using regular expressions.
Each character represents a step in the automaton.
Before the decimal point — because in Python, a float can be 1. or 1.0, the characters after the decimal point are optional.
jero98772
(Jero98772)
July 15, 2025, 8:35pm
29
Oh wow. Yeah, then no, this is never worth xD.
I don’t know if optimizing two operations is such a bad thing if it’s for the most widely used interpreter. Keep in mind that this can also have an impact in a loop — in terms of time and energy consumption.
bwoodsend
(Brénainn Woodsend)
July 15, 2025, 9:59pm
30
Yes, but that all happens once per literal float at bytecode compile time. Not every time you pass a float to a function.
3 Likes