Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concept of Tuple in Python3 #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions data_structures/Tuple.py
Original file line number Diff line number Diff line change
@@ -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