Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个功能base36-2check,
base36-2check
并且用户可以输入一个字符串,我将如何检查该字符串是否为 base36?
捕获int构造函数的异常,如下所示:
int
In [3]: try: ...: int('abc!d', 36) ...: except ValueError: ...: print "Nope"
示例程序:
def base36_check(s): try: int(s, 36) return True except ValueError: return False print base36_check('abcdefg') print base36_check('abc!efg')