0% found this document useful (0 votes)
5 views

Tuples in python

The presentation explains Python tuples, which are immutable sequences of values indexed by integers. It covers how to create, access, and manipulate tuples, including methods like count() and index(). Additionally, it highlights the differences between tuples, lists, and dictionaries in terms of mutability and access methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Tuples in python

The presentation explains Python tuples, which are immutable sequences of values indexed by integers. It covers how to create, access, and manipulate tuples, including methods like count() and index(). Additionally, it highlights the differences between tuples, lists, and dictionaries in terms of mutability and access methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

PYTHON TUPLES

a presentation by :
Anna Marie Balcaso and Eullaine Caballero
WHAT IS TUPLE?
WHAT IS TUPLE?

A tuple is a sequence of values,


which can be of any type and they are indexed
by integer. Tuples are just like list, but we can’t
change values of tuples in place. Thus tuples are
immutable.
The index value of tuple starts from 0.
A tuple consists of a number of values separated
by commas. For example:
T=(10, 20, 30, 40)
print (T)
10, 20, 30, 40
CREATING EMPTY TUPLE
CREATING EMPTY TUPLE
ACCESSING TUPLE
ACCESSING TUPLE
ACCESSING TUPLE USING LOOPS
ACCESSING TUPLE USING LOOPS
ACCESSING TUPLE USING LOOPS

OUTPUT
CHECK IF ITEM EXISTS
CHECK IF ITEM EXISTS

OUTPUT
TUPLE LENGTH
TUPLE LENGTH

OUTPUT
REMOVING A TUPLE
REMOVING A TUPLE

You cannot remove or delete or update


items in a tuple.

Tuples are unchangeable, so you


cannot remove items from it, but you can
delete the tuple completely:

NOTE: TUPLES ARE IMMUTABLE


TUPLE METHODS
TUPLE METHODS

Python provides two built-in


methods that you can use on tuples.

1. count() Method

2. index() Method
TUPLE METHODS

1. count() Method
Return the number of times the value
appears in the tuple Count()
method
returns
total no
times
‘banana’
present in
the given
tuple
TUPLE METHODS

2. index() Method

index()
Method

index() Method returns index of


“banana” i.e 1
DIFFERENCE BETWEEN
LIST AND TUPLE
DIFFERENCE BETWEEN LIST AND TUPLE
LIST TUPLE
Syntax for list is slightly Syntax for tuple is slightly
different comparing with different comparing with
tuple lists

Weekdays=[‘Sun’,’Mon’, twdays = (‘Sun’, ‘mon', ‘tue',


‘wed’,46,67] 634)
type(Weekdays) type(twdays)
class<‘lists’> class<‘tuple’>

List uses [ and ] (square Tuple uses rounded


brackets) to bind the brackets( and ) to bind the
elements. elements.
DIFFERENCE BETWEEN LIST AND TUPLE

LIST TUPLE
List can be edited once it A tuple is a list which one
is created in python. Lists cannot edit once it is
are mutable data created in Python code. The
structure. tuple is an immutable data
structure

More methods or Compare to lists tuples have


functions are associated Less methods or functions.
with lists.
DIFFERENCE BETWEEN
TUPLE AND DICTIONARY
DIFFERENCE BETWEEN TUPLE AND DICTIONARY

TUPLE DICTIONARY
Order is maintained. Ordering is not guaranteed.

They are immutable Values in a dictionary can be


changed.

They can hold any type, Every entry has a key and a
and types can be mixed. value
DIFFERENCE BETWEEN TUPLE AND DICTIONARY

TUPLE DICTIONARY
Elements are accessed Elements are accessed using
via numeric (zero based) key's values
indices

There is a difference in Differ in syntax, looks bit


syntax and looks easy to complicated when compare
define tuple with Tuple or lists
THANK YOU!!!

You might also like