介绍
这篇文章将为大家详细讲解有关python中要怎样使用断言断言语句,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
<强> 强> <强> 强> <强> 强> <强> 强> <强> 强>
def strToInt10 (x): ,,,assert isinstance (x,, str), & # 39; x must be 字符串# 39; ,,,assert x.isdigit (), & # 39; x must be 数字# 39; ,,,return int (x) 打印(strToInt10 (& # 39; 10 & # 39;)) strToInt10 ([1])
<强> 强> <强> 强>
10 ---- AssertionError ,,,,,,,,,,,,,,,,,,,,,,,,,,, Traceback (most recent 调用 & lt; ipython-input-24-23ea36418da1>, strToInt10拷贝(x) ,,,,,1,def strToInt10 (x): ——祝辞,2,,,,,assert isinstance (x,, str), & # 39; x must be 字符串# 39; ,,,,,3,,,,,assert x.isdigit (), & # 39; x must be 数字# 39; ,,,,,4,,,,,return int (x) ,,,,,5,打印(strToInt10 (& # 39; 10 & # 39;)) , AssertionError: x must  be 字符串
关于python中要怎样使用断言断言语句就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看的到。