Created
April 20, 2021 17:04
-
-
Save 29akshay/7690642f941bc62178f81869214198bf to your computer and use it in GitHub Desktop.
jupiter_study/python notebooks/Untitled2.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": {}, | |
"cell_type": "raw", | |
"source": "2) Access value 20 from the following tuple\n aTuple = (\"Orange\", [10, 20, 30], (5, 15, 25))\n" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "aTuple=(\"orange\",[10,20,30],(5,15,25))\nprint(aTuple[1][1])\n", | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "20\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "raw", | |
"source": "3) Unpack the following tuple into 4 variables\naTuple = (10, 20, 30, 40)\n" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "aTuple=(10,20,30,40)\na,b,c,d=aTuple\nprint(a)\nprint(b)\nprint(c)\nprint(d)\n", | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "10\n20\n30\n40\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "raw", | |
"source": "4) Copy element 44 and 55 from the following tuple into a new tuple\n tuple1 = (11, 22, 33, 44, 55, 66)\n" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "tuple1=(11,22,33,44,55,66)\ntuple2=tuple1[3:-1]\nprint(tuple2)\n", | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "(44, 55)\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "raw", | |
"source": "5) Counts the number of occurrences of item 50 from a tuple\n tuple1 = (50, 10, 60, 70, 50)\n" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "tuple1=(50,10,60,70,50)\nprint(tuple1.count(50))\n", | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "2\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "raw", | |
"source": "6) Modify the first item (22) of a list inside a following tuple to 222\n tuple1 = (11, [22, 33], 44, 55)\n" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "tuple1=(11,[22,33],44,55)\ntuple1[1][0]=222\nprint(tuple1)\n", | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "(11, [222, 33], 44, 55)\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "raw", | |
"source": "7) Swap the following two tuples\n tuple1 = (11, 22)\ntuple2 = (99, 88)\n" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "tuple1=(11,22)\ntuple2=(99,88)\ntuple1,tuple2=tuple2,tuple1\nprint(tuple1)\nprint(tuple2)\n", | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "(99, 88)\n(11, 22)\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "raw", | |
"source": "8) Reverse the following tuple\naTuple = (10, 20, 30, 40, 50)\n" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "aTuple=(10,20,30,40,50)\nprint(aTuple[::-1])\n", | |
"execution_count": 7, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "(50, 40, 30, 20, 10)\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.8.5", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "jupiter_study/python notebooks/Untitled2.ipynb", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment