본문 바로가기
나는 이렇게 학습한다/Algorithm & SQL

0203. Parse float

by daco2020 2023. 2. 3.

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