Skip to content

Commit 6d11700

Browse files
committed
Updated with Tuples
1 parent be8f0c0 commit 6d11700

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

basics.ipynb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,59 @@
471471
"my_dict.keys()"
472472
]
473473
},
474+
{
475+
"cell_type": "markdown",
476+
"metadata": {},
477+
"source": [
478+
"<div class=\"alert alert-block alert-info\">\n",
479+
"<b>1.b. Tuples</b>\n",
480+
"A tuple is a fixed size grouping of elements, such as an (x, y) co-ordinate. Tuples are like lists, except they are immutable and do not change size (tuples are not strictly immutable since one of the contained elements could be mutable). Tuples play a sort of \"struct\" role in Python -- a convenient way to pass around a little logical, fixed size bundle of values. A function that needs to return multiple values can just return a tuple of the values. For example, if I wanted to have a list of 3-d coordinates, the natural python representation would be a list of tuples, where each tuple is size 3 holding one (x, y, z) group.\n",
481+
"</div>"
482+
]
483+
},
484+
{
485+
"cell_type": "code",
486+
"execution_count": 23,
487+
"metadata": {},
488+
"outputs": [
489+
{
490+
"data": {
491+
"text/plain": [
492+
"(1, 2, 3)"
493+
]
494+
},
495+
"execution_count": 23,
496+
"metadata": {},
497+
"output_type": "execute_result"
498+
}
499+
],
500+
"source": [
501+
"# A Sample Tuple\n",
502+
"my_tuple = (1, 2, 3)\n",
503+
"my_tuple"
504+
]
505+
},
506+
{
507+
"cell_type": "code",
508+
"execution_count": 24,
509+
"metadata": {},
510+
"outputs": [
511+
{
512+
"data": {
513+
"text/plain": [
514+
"1"
515+
]
516+
},
517+
"execution_count": 24,
518+
"metadata": {},
519+
"output_type": "execute_result"
520+
}
521+
],
522+
"source": [
523+
"# To reference any element in tuple\n",
524+
"my_tuple[0]"
525+
]
526+
},
474527
{
475528
"cell_type": "code",
476529
"execution_count": null,

0 commit comments

Comments
 (0)