How to I check that a string contains only digits and / in python?
问题 I am trying to check that a string contains only / and digits, to use as a form of validation, however I cannot find and way to do both. ATM I have this: if Variable.isdigit() == False: This works for the digits but I have not found a way to check also for the slashes. 回答1: There are many options, as showed here. A nice one would be list comprehensions. Let's consider two strings, one that satisfies the criteria, other that doesn't: >>> match = "123/456/" >>> no_match = "123a456/" We can