나는 이렇게 학습한다/Algorithm & SQL

0203. Parse float

daco2020 2023. 2. 3. 20:47
반응형

Write function parse_float which takes a string/list and returns a number or 'none' if conversion is not possible.



Solution:

def parse_float(string: str) -> float | None:
    try:
        return float(string)
    except (ValueError, TypeError):
        return None


반응형