Skip to content

Commit 86ab9f2

Browse files
authored
Explain type(x)
1 parent bc913a1 commit 86ab9f2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

classes.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ string.
3737
>>>
3838
```
3939

40+
We can also get an instance's class with `type()`:
41+
42+
```py
43+
>>> type('')
44+
<class 'str'>
45+
>>> type(0)
46+
<class 'int'>
47+
>>> type([])
48+
<class 'list'>
49+
>>> type({})
50+
<class 'dict'>
51+
>>>
52+
```
53+
4054
Let's say you make a program that processes data about websites. With a
4155
custom class, you're not limited to `str`, `int` and other classes
4256
Python comes with. Instead you can define a Website class, and make

0 commit comments

Comments
 (0)