-
Notifications
You must be signed in to change notification settings - Fork 0
/
typeCheck.py
37 lines (27 loc) · 905 Bytes
/
typeCheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Creat a Class
class Book:
# the "init" function is called when the instance is
# created and ready to be initialized
def __init__(self , name ):
self.title = name
# creat instances methods
#Creat another Class
class NewsPaper:
def __init__(self , name):
self.title = name
# Creat Some instances of the Classes
b1 = Book("The Catcher in the Rye")
b2 = Book("THe Grapes of Wrath")
n1 = NewsPaper("The Dawn")
n2 = NewsPaper("The News")
# use type() to inspect the Object type
print(type(b1))
print(type(n1))
# Compare Two types togather
print(type(b1) == type(b2))
print(type(b1) == type(n2))
# use "isinstance" to compare a specific instance tp a knowm type
print(isinstance(b1 , Book))
print(isinstance(n1 , NewsPaper))
print(isinstance(b1 , NewsPaper))
print(isinstance(n2 , object)) #object is default in python as every thing in pytho is an object