You are on page 1of 10

Acknowledgement

I would like to express my special thanks of gratitude to my computer teacher


Mr. Hrudananda Mohanta as well as our principal Mr. Rajendra Prasad Sah
who
gave me the golden opportunity to do this wonderful project on the topic,
which also helped me in doing a lot of Research and I came to know about so
many new things I am really thankful to them.
Secondly I would also like to thank my parents and friends who helped me a
lot
in finalizing this project within the limited time frame.
Contents
What is Tuple
How it's used
Creating a tuple
Concatenation of Tuples
Slicing of Tuple
Deleting a tuple
What is Tuple
A tuple is a collection of objects which ordered
and immutable. Tuples are sequences, just like
lists. The differences between tuples and lists
are, the tuples cannot be changed unlike lists
and tuples use parentheses, whereas lists use
square brackets.
Creating a tuple is as simple as putting different
comma-separated values. Optionally you can
put these comma-separated values between
parentheses also.
How it's used
Tuples are used to store multiple items in a single
variable. Tuple is one of 4 built-in data types in
Python used to store collections of data, the other
3 are List, Set, and Dictionary, all with different
qualities and usage. A tuple is a collection which is
ordered and unchangeable.
Creating a Tuple

# An empty tuple tup = 'python', 'geeks'


print(tup)
empty_tuple = ()

print (empty_tuple) # Another for doing the same


tup = ('python', 'geeks')
print(tup)
Output:

Output:
()
('python', 'geeks')

('python', 'geeks')

Concatenation of Tuples
tuple1 = (0, 1, 2, 3)
tuple2 = ('python', 'geek')

# Concatenating above two


print(tuple1 + tuple2)

Output:
(0, 1, 2, 3, 'python', 'geek')

Slicing of Tuple
Slicing of a Tuple is done to fetch a specific range or slice of
sub-elements from a Tuple. Slicing can also be done to lists
and arrays. Indexing in a list results to fetching a single
element whereas Slicing allows to fetch a set of elements.
Note- Negative Increment values can also be used to reverse
the sequence of Tuples.

Tuple1 = tuple('GEEKSFORGEEKS')

Output:
# Removing First element Removal of First Element:
print("Removal of First Element: ") ('E', 'E', 'K', 'S', 'F', 'O', 'R', 'G', 'E', 'E', 'K', 'S')
print(Tuple1[1:])


Tuple after sequence of Element is reversed:
# Reversing the Tuple ('S', 'K', 'E', 'E', 'G', 'R', 'O', 'F', 'S', 'K', 'E', 'E', 'G')
print("\nTuple after sequence of Element is reversed: ")

print(Tuple1[::-1]) Printing elements between Range 4-9:



('S', 'F', 'O', 'R', 'G')
# Printing elements of a Range

print("\nPrinting elements between Range 4-9: ")


print(Tuple1[4:9])

DELETING A TUPLE
Tuples are immutable and cannot be deleted, but deleting
tuple entirely is possible by using the keyword "del".
For example,
tl-(4. 6. 3. 7. 6. 5. 0) print("Tuple is :". tl)
del (tl)
print("Tuple after deleting") print (t1)
Output
Tuple is: (4, 6, 3, 7, 6, 5, 0)
Tuple after deleting Trackback (most recent call last):
File "<pyshell#6>", line 1, in <module>
print(t1)
NameError: name 'tl' is not defined
CONCLUSION
So after completion of the project topic
"tuple" i learned many things what's is tuple
and how it's work in python, what kind of
things we can actually do in this,
So i conclude my project here i hope, you will
like it.

THANK YOU

You might also like