assert陳述句是一種插入除錯斷點到程式的一種便捷的方式,
assert 3 == 3 assert 1 == True assert (4 == 4) print('-----------') assert (3 == 4) ''' 拋出AssertionError例外,后面程式不執行 ''' print('-----------')
isinstance函式說明:
當我們定義一個class的時候,我們實際上就定義了一種資料型別,我們定義的資料型別和Python自帶的資料型別,比如str、list、dict沒什么兩樣:
判斷一個變數是否是某個型別可以用isinstance()判斷:
class Student(): def __init__(self, name, score): self.name = name self.score = score a = '10' b = 3 c = [1, 2, 3] d = (1, 2, 3) f = Student('Eden', 99.9)
print(isinstance(a, str)) # True
print(isinstance(b, int)) # True
print(isinstance(c, list)) # True
print(isinstance(d, tuple)) # True
print(isinstance(f, Student)) # True
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/196582.html
標籤:Python
上一篇:[python]Python 中 if not 用法
下一篇:Python 生成隨機圖片驗證碼
