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