Skip to content

Commit 080e4f2

Browse files
committed
Special functions
1 parent c452cae commit 080e4f2

File tree

2 files changed

+232
-0
lines changed

2 files changed

+232
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 39,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"class Book():\n",
10+
" def __init__(self,title,author,pages):\n",
11+
" self.title = title\n",
12+
" self.author = author\n",
13+
" self.pages = pages\n",
14+
" def __str__(self):\n",
15+
" return f'{self.title} by {self.author}'\n",
16+
" def __len__(self):\n",
17+
" return self.pages\n",
18+
" def __del__(self):\n",
19+
" print('A book has been deleted')"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 45,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"b = Book('Selfish Gene','Richard Dawkins',500)"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": 46,
34+
"metadata": {},
35+
"outputs": [
36+
{
37+
"name": "stdout",
38+
"output_type": "stream",
39+
"text": [
40+
"Selfish Gene by Richard Dawkins\n"
41+
]
42+
}
43+
],
44+
"source": [
45+
"print(b)"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": 47,
51+
"metadata": {},
52+
"outputs": [
53+
{
54+
"data": {
55+
"text/plain": [
56+
"500"
57+
]
58+
},
59+
"execution_count": 47,
60+
"metadata": {},
61+
"output_type": "execute_result"
62+
}
63+
],
64+
"source": [
65+
"len(b)"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": 48,
71+
"metadata": {},
72+
"outputs": [
73+
{
74+
"name": "stdout",
75+
"output_type": "stream",
76+
"text": [
77+
"A book has been deleted\n"
78+
]
79+
}
80+
],
81+
"source": [
82+
"del b"
83+
]
84+
},
85+
{
86+
"cell_type": "code",
87+
"execution_count": null,
88+
"metadata": {
89+
"collapsed": true
90+
},
91+
"outputs": [],
92+
"source": []
93+
}
94+
],
95+
"metadata": {
96+
"kernelspec": {
97+
"display_name": "Python 3",
98+
"language": "python",
99+
"name": "python3"
100+
},
101+
"language_info": {
102+
"codemirror_mode": {
103+
"name": "ipython",
104+
"version": 3
105+
},
106+
"file_extension": ".py",
107+
"mimetype": "text/x-python",
108+
"name": "python",
109+
"nbconvert_exporter": "python",
110+
"pygments_lexer": "ipython3",
111+
"version": "3.6.1"
112+
}
113+
},
114+
"nbformat": 4,
115+
"nbformat_minor": 2
116+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 39,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"class Book():\n",
10+
" def __init__(self,title,author,pages):\n",
11+
" self.title = title\n",
12+
" self.author = author\n",
13+
" self.pages = pages\n",
14+
" def __str__(self):\n",
15+
" return f'{self.title} by {self.author}'\n",
16+
" def __len__(self):\n",
17+
" return self.pages\n",
18+
" def __del__(self):\n",
19+
" print('A book has been deleted')"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 45,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"b = Book('Selfish Gene','Richard Dawkins',500)"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": 46,
34+
"metadata": {},
35+
"outputs": [
36+
{
37+
"name": "stdout",
38+
"output_type": "stream",
39+
"text": [
40+
"Selfish Gene by Richard Dawkins\n"
41+
]
42+
}
43+
],
44+
"source": [
45+
"print(b)"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": 47,
51+
"metadata": {},
52+
"outputs": [
53+
{
54+
"data": {
55+
"text/plain": [
56+
"500"
57+
]
58+
},
59+
"execution_count": 47,
60+
"metadata": {},
61+
"output_type": "execute_result"
62+
}
63+
],
64+
"source": [
65+
"len(b)"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": 48,
71+
"metadata": {},
72+
"outputs": [
73+
{
74+
"name": "stdout",
75+
"output_type": "stream",
76+
"text": [
77+
"A book has been deleted\n"
78+
]
79+
}
80+
],
81+
"source": [
82+
"del b"
83+
]
84+
},
85+
{
86+
"cell_type": "code",
87+
"execution_count": null,
88+
"metadata": {
89+
"collapsed": true
90+
},
91+
"outputs": [],
92+
"source": []
93+
}
94+
],
95+
"metadata": {
96+
"kernelspec": {
97+
"display_name": "Python 3",
98+
"language": "python",
99+
"name": "python3"
100+
},
101+
"language_info": {
102+
"codemirror_mode": {
103+
"name": "ipython",
104+
"version": 3
105+
},
106+
"file_extension": ".py",
107+
"mimetype": "text/x-python",
108+
"name": "python",
109+
"nbconvert_exporter": "python",
110+
"pygments_lexer": "ipython3",
111+
"version": "3.6.1"
112+
}
113+
},
114+
"nbformat": 4,
115+
"nbformat_minor": 2
116+
}

0 commit comments

Comments
 (0)