Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5cd15b4

Browse files
Merge pull request #6 from binamify/main
Created Difference between type() and instance().py
2 parents f2d31c8 + 08b8ac7 commit 5cd15b4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Polygon:
2+
def sides_no(self):
3+
pass
4+
5+
class Triangle(Polygon):
6+
def area(self):
7+
pass
8+
9+
obj_polygon = Polygon()
10+
obj_triangle = Triangle()
11+
12+
print(type(obj_triangle) == Triangle) # true
13+
print(type(obj_triangle) == Polygon) # false
14+
15+
print(isinstance(obj_polygon, Polygon)) # true
16+
print(isinstance(obj_triangle, Polygon)) # true

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /