From 7a9d9c6c589f70221a116faf8b1fbbd63ea29b05 Mon Sep 17 00:00:00 2001 From: jaideep6214 <43785047+jaideep6214@users.noreply.github.com> Date: Wed, 9 Oct 2019 21:15:29 +0530 Subject: [PATCH] Concept of Tuple in Python3 --- data_structures/Tuple.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 data_structures/Tuple.py diff --git a/data_structures/Tuple.py b/data_structures/Tuple.py new file mode 100644 index 0000000..8bdc9b6 --- /dev/null +++ b/data_structures/Tuple.py @@ -0,0 +1,36 @@ +#Creation of a tuple +Tuple=tuple() + +#Insertion of an element +Tuple=Tuple+(1,) + +#Accessing an element +tup1 = ('physics', 'chemistry', 1997, 2000) +tup2 = (1, 2, 3, 4, 5, 6, 7 ) + +print ("tup1[0]: ", tup1[0]) +print ("tup2[1:5]: ", tup2[1:5]) + +#This will give the result as: +#tup1[0]: physics +#tup2[1:5]: (2, 3, 4, 5) + +#Creating a new Tuple by existing tuples +tup1 = (12, 34.56) +tup2 = ('abc', 'xyz') + +# Following action is not valid for tuples +# tup1[0] = 100; + +# So let's create a new tuple as follows +tup3 = tup1 + tup2 +print (tup3) + +#This will be the result +#(12, 34.56, 'abc', 'xyz') + +#Deletion of a tuple +del tup; +print ("After deleting tup : ") +print (tup) +# It will give an error as tuple is deleted