나는 이렇게 학습한다/Algorithm & SQL
0210. Is it a number?
daco2020
2023. 2. 10. 23:32
반응형
Given a string s, write a method (function) that will return true if its a valid single integer or floating number or false if its not.
Valid examples, should return true:
isDigit("3")
isDigit(" 3 ")
isDigit("-3.23")
should return false:
isDigit("3-4")
isDigit(" 3 5")
isDigit("3 5")
isDigit("zero")
Solution:
def isDigit(string: str) -> bool:
return string.strip().lstrip("-").replace(".", "").isdigit()
반응형