0

How can I check in Python whether a number is built in this pattern:

1. 57.00057  
2. 611.000000611  
3. 389.00003890000389

There's the number, then a certain number of zero's after the dot and then the number again. This can occur multiply times after the dot (Like in example 3).

1 Answer 1

4
def test(number):
    return bool(re.match(r'^(\d+)\.(0+\1)+$', number))
Sign up to request clarification or add additional context in comments.

1 Comment

Nice and compact, Daniel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.