Skip to content

Commit d79a111

Browse files
Add files via upload
1 parent 7f7bb03 commit d79a111

File tree

2 files changed

+914
-0
lines changed

2 files changed

+914
-0
lines changed

04_Tuple.ipynb

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Tuple\n",
8+
"- Definition\n",
9+
"- Examples\n",
10+
"- Concatenation\n",
11+
"- Repetition\n",
12+
"- Indexing\n",
13+
"- Slicing\n",
14+
"- List Vs Tuples\n",
15+
"- Benefit of using tuple\n",
16+
"- Available Methods"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": 1,
22+
"metadata": {},
23+
"outputs": [
24+
{
25+
"name": "stdout",
26+
"output_type": "stream",
27+
"text": [
28+
"()\n"
29+
]
30+
}
31+
],
32+
"source": [
33+
"a = ()\n",
34+
"print(a)"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 2,
40+
"metadata": {},
41+
"outputs": [
42+
{
43+
"name": "stdout",
44+
"output_type": "stream",
45+
"text": [
46+
"<class 'int'>\n"
47+
]
48+
}
49+
],
50+
"source": [
51+
"a = (1)\n",
52+
"print(type(a))"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 3,
58+
"metadata": {},
59+
"outputs": [
60+
{
61+
"name": "stdout",
62+
"output_type": "stream",
63+
"text": [
64+
"<class 'tuple'>\n"
65+
]
66+
}
67+
],
68+
"source": [
69+
"a = (1,)\n",
70+
"print(type(a))"
71+
]
72+
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": 4,
76+
"metadata": {},
77+
"outputs": [
78+
{
79+
"data": {
80+
"text/plain": [
81+
"(1, 2, 3, 4, 5)"
82+
]
83+
},
84+
"execution_count": 4,
85+
"metadata": {},
86+
"output_type": "execute_result"
87+
}
88+
],
89+
"source": [
90+
"a = (1,2,3,4,5)\n",
91+
"a"
92+
]
93+
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": 5,
97+
"metadata": {},
98+
"outputs": [
99+
{
100+
"name": "stdout",
101+
"output_type": "stream",
102+
"text": [
103+
"['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']\n"
104+
]
105+
}
106+
],
107+
"source": [
108+
"print(dir(a))"
109+
]
110+
},
111+
{
112+
"cell_type": "code",
113+
"execution_count": 6,
114+
"metadata": {},
115+
"outputs": [
116+
{
117+
"name": "stdout",
118+
"output_type": "stream",
119+
"text": [
120+
"(1, 2, 3, 4, [6, 7, 8], 9, 10)\n"
121+
]
122+
}
123+
],
124+
"source": [
125+
"a = (1,2,3,4,[6,7,8],9,10)\n",
126+
"print(a)"
127+
]
128+
},
129+
{
130+
"cell_type": "code",
131+
"execution_count": 7,
132+
"metadata": {},
133+
"outputs": [
134+
{
135+
"ename": "AttributeError",
136+
"evalue": "'tuple' object has no attribute 'append'",
137+
"output_type": "error",
138+
"traceback": [
139+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
140+
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
141+
"\u001b[0;32m<ipython-input-7-6e5e5846bb2a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0ma\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
142+
"\u001b[0;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'"
143+
]
144+
}
145+
],
146+
"source": [
147+
"a.append(10)"
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": 8,
153+
"metadata": {},
154+
"outputs": [
155+
{
156+
"data": {
157+
"text/plain": [
158+
"(1, 2, 3, 4, [6, 7, 8], 9, 10)"
159+
]
160+
},
161+
"execution_count": 8,
162+
"metadata": {},
163+
"output_type": "execute_result"
164+
}
165+
],
166+
"source": [
167+
"a"
168+
]
169+
},
170+
{
171+
"cell_type": "code",
172+
"execution_count": 10,
173+
"metadata": {},
174+
"outputs": [
175+
{
176+
"data": {
177+
"text/plain": [
178+
"8"
179+
]
180+
},
181+
"execution_count": 10,
182+
"metadata": {},
183+
"output_type": "execute_result"
184+
}
185+
],
186+
"source": [
187+
"a[4].pop()"
188+
]
189+
},
190+
{
191+
"cell_type": "code",
192+
"execution_count": 11,
193+
"metadata": {},
194+
"outputs": [
195+
{
196+
"data": {
197+
"text/plain": [
198+
"(1, 2, 3, 4, [6, 7], 9, 10)"
199+
]
200+
},
201+
"execution_count": 11,
202+
"metadata": {},
203+
"output_type": "execute_result"
204+
}
205+
],
206+
"source": [
207+
"a"
208+
]
209+
},
210+
{
211+
"cell_type": "code",
212+
"execution_count": 13,
213+
"metadata": {},
214+
"outputs": [
215+
{
216+
"data": {
217+
"text/plain": [
218+
"6"
219+
]
220+
},
221+
"execution_count": 13,
222+
"metadata": {},
223+
"output_type": "execute_result"
224+
}
225+
],
226+
"source": [
227+
"a[4][0]"
228+
]
229+
},
230+
{
231+
"cell_type": "code",
232+
"execution_count": 12,
233+
"metadata": {},
234+
"outputs": [
235+
{
236+
"data": {
237+
"text/plain": [
238+
"(1, 2, 3, 4, [6, 7, [10, 20, 30]], 9, 10)"
239+
]
240+
},
241+
"execution_count": 12,
242+
"metadata": {},
243+
"output_type": "execute_result"
244+
}
245+
],
246+
"source": [
247+
"a[4].append([10,20,30])\n",
248+
"a"
249+
]
250+
},
251+
{
252+
"cell_type": "code",
253+
"execution_count": null,
254+
"metadata": {},
255+
"outputs": [],
256+
"source": []
257+
}
258+
],
259+
"metadata": {
260+
"kernelspec": {
261+
"display_name": "Python 3",
262+
"language": "python",
263+
"name": "python3"
264+
},
265+
"language_info": {
266+
"codemirror_mode": {
267+
"name": "ipython",
268+
"version": 3
269+
},
270+
"file_extension": ".py",
271+
"mimetype": "text/x-python",
272+
"name": "python",
273+
"nbconvert_exporter": "python",
274+
"pygments_lexer": "ipython3",
275+
"version": "3.7.4"
276+
}
277+
},
278+
"nbformat": 4,
279+
"nbformat_minor": 2
280+
}

0 commit comments

Comments
 (0)