Revised TUPLE in Python
Revised TUPLE in Python
Concatenation refers
to Joining of two Tuple CAN be concatenated or
objects joined with another Tuple
OPERATIONS on Tuple Replication
CONTENTS
Tuples Introduction: Replication refers to Repetition of objects as it
OPERATIONS is. Here, in TUPLE we can see NON-
ON Tuple VECTORISED operation with a tuple where the
entire tuple as a whole is replicated.
Concatenation/Joining
Repetition/ NOTE: Vectorised operation, refers to the
Replication replication of individual elements of the object.
Membership
Comparison of Tuples Replicating the unnamed
Functions/methods Tuple two times
Tuples Slicing;
Nested Tuples;
finding the maximum,
minimum, mean
linear search on Tuple
Replicating the named Tuple RL
counting the frequency
four times
OPERATIONS on Tuple Membership
Membership operator tests for Membership in a sequence.
CONTENTS Returns Boolean True or False
Tuples Introduction: OPERATOR DESCRIPTION
OPERATIONS
in Results to True value if it finds a variable at the LHS of in
ON Tuple operator in the sequence mentioned in the RHS of the in
operator, else it returns False
Concatenation/Joining
Repetition/ not in Results to True value if it does not find a variable at the
Replication LHS of in operator in the sequence mentioned in the RHS
of the in operator, else it returns False
Membership
in Tuple
Comparison of Tuples
Functions/methods
Tuples Slicing;
Nested Tuples;
finding the maximum,
minimum, mean
linear search on Tuple
counting the frequency
OPERATIONS on Comparison of Tuple
CONTENTS Comparison of Tuple returns Boolean True or False.
Relational operators
Tuples Introduction:
==,!=,<,<=,>,>= are used
OPERATIONS in comparing two objects.
ON Tuple Here, for example two
Tuple objects are
Concatenation/Joining compared.
Repetition/
Relational operators ==,!=
Replication
can be used in comparing
Membership in
two objects eg. Tuple with
Tuple
number/string/tuple. But,
Comparison Relational operators
<,<=,>,>= always returns
of Tuples ERROR when used in
Functions/methods
Tuples Slicing;
comparing two objects eg.
Nested Tuples; Tuple with
finding the maximum, number/string/tuple.
minimum, mean Eg. Tuple CANNOT be
linear search on Tuple compared with a number
counting the frequency
Functions / Methods on Tuple-len()
CONTENTS len() function counts the no. of elements in the Tuple
Tuples Introduction:
Operations on a Tuple
Functions/
methods
len(), tuple(), count(),
index(), sorted(),min(),
max(), sum()
Tuples Slicing;
Nested Tuples;
finding the maximum,
minimum, mean TOTAL 5 elements of the Tuple object
linear search on Tuple
counting the frequency
Functions / Methods on Tuple-tuple()
CONTENTS The tuple() function creates a Tuple object.
A Tuple object is a collection which is ordered and
changeable.
Tuples Introduction:
tuple() function
Operations on a Tuple takes
Functions/m elements/values
inside the
ethods parantheses i.e. ()
len(), tuple(),
count(), index(),
sorted(),min(), max(), sum()
Tuples Slicing;
Nested Tuples;
finding the maximum,
minimum, mean
linear search on Tuple
counting the frequency NOTE: Python language is case-sensitive.
Here, Z is the Tuple object , so, z in small letters gives an error.
Functions / Methods on Tuple- count()
CONTENTS count( ) method,
returns the count of the item (no. of times the
Tuples Introduction:
item /element/value appears) that is passed as
Operations on a Tuple
argument. If the given item is not in the
Functions/ Tuple, it will return 0
methods
len(), tuple(),
count(), index(),
sorted(),min(), max(),
sum()
Tuples Slicing;
Nested Tuples;
finding the maximum,
minimum, mean
linear search on Tuple
counting the frequency
Functions / Methods on Tuple- index()
CONTENTS index( ) method, returns the index of
the first matched item in the Tuple
Tuples Introduction:
Operations on a Tuple Forward
Index 0 1 2 3 4 5
Functions/
methods
len(), tuple(), count(),
index(), sorted(),min(),
max(), sum()
Tuples Slicing;
Nested Tuples;
finding the maximum,
minimum, mean
linear search on Tuple
counting the frequency
Functions / Methods on Tuple- sorted()
CONTENTS sorted( ) method,
sorted( ) method and sorted(reverse=True) sorts or
Tuples Introduction:
orders the items of the Tuple, by default in increasing order.
Operations on a Tuple
sorted(reverse=True ) for getting the Tuple in decreasing order
Functions
/ methods
len(), tuple(), count(),
Tuples Slicing;
Nested Tuples;
finding the maximum,
minimum, mean
linear search on Tuple
counting the frequency
Functions / Methods on Tuple- min(),max(),sum() contd..
Tuple of string . Maximum and
Minimum is done on the basis
of the ASCII values of the
characters from the beginning.
Eg. ‘A’=65, ‘a’ = 97, ‘b’=98 and
so on
A Tuple with
mixed data
type cannot
return values
for the min,
max and
sum
functions.
NOTE
Unlike a List object,
an object of Tuple do not have the following
methods:
– Reverse()
– Append()
– Extend()
– Clear()
– Remove()
– Pop()
Tuple slicing
L[start:stop] creates a Tuple slice out of Tuple T with elements falling between
indexes start and stop, not including value at the stop index.
Start index 5, stop index is 50 which is beyond the last index in forward
direction. Hence, it will stop at the last index
Start index 10, stop index is 30 which is beyond the last index
in forward direction. Hence, it will stop at the last index
Start index -20(which is beyond backward index,) stop index is -5 which takes value till
(-5-1=-6). Here, -6 is ‘N’.
Default start and stop is beginning and end index of the Tuple. Here, step is 3.
NESTED Tuples
A Tuple within a Tuple is Nested Tuple.
CONTENTS
Tuples Intro Enclosing Tuple
Operations on a Tuple
Functions/methods
Tuples Slicing;
Nested Tuple 1 Nested Tuple 2
Nested
Tuples;
finding the maximum,
minimum, mean
linear search on Tuple
counting the frequency
Note: Denoting Nested elements
using Index nos.
M[0] 10
M[1] [15,30]
M[1][0]15
M[1][1]30
M[2] *80,’Mask’,60+
M[2][0]80
M[2][1]‘Mask’
M[2][2]60
Program to find the MAXIMUM element from a Tuple of element along
with its index in the Tuple without using max() library function
CONTENTS
Tuples Intro
Operations on NOTE: We are not taking
a Tuple
append method as Tuple is
Functions/
methods
immutable. So, declare the
Tuples Slicing; tuple beforehand
Nested Tuples;
finding
the
maximum
, minimum, mean
linear search
on Tuple OUTPUT
counting the
frequency
Program to find the MINIMUM element from a Tuple of element along
with its index in the Tuple without using min() library function
CONTENTS
Tuples Intro
Operations on a
Tuple
Functions/
methods
Tuples Slicing;
Nested Tuples;
finding
the
minimum,
maximum , mean
linear search
on Tuple OUTPUT
counting the
frequency
Program to find the MEAN (AVERAGE) of all the elements of
the Tuple
CONTENTS
Tuples Intro
Operations on a
Tuple
Functions/
methods
Tuples Slicing;
Nested Tuples;
finding
the mean,
maximum,
minimum
linear search
on Tuple
counting the OUTPUT
frequency
Program to search an element in the Tuple (LINEAR SEARCH)
CONTENTS
Tuples Intro
Operations on a
Tuple
Functions/
methods
Tuples Slicing;
Nested Tuples;
finding the
mean, maximum,
minimum
linear
search on
Tuple
counting the
frequency
OUTPUT
Program to count frequency (/no. of times of occurrence) of an element in the Tuple
(FREQUENCY COUNT)
CONTENTS
Tuples Intro
Operations on a
Tuple
Functions/
methods
Tuples Slicing;
Nested Tuples;
finding the
mean, maximum,
minimum
linear search
on Tuple
counting
the
frequency
OUTPUT
Bibliograhy and References
• Google
• Wikipedia
• XI Computer Science , By Sumita Arora,
Dhanpat Rai Publication 2020 Edition
• XI Informatics Practices , By Sumita Arora,
Dhanpat Rai Publication 2020 Edition
Programming is an ART….
Add your colours to it and make your own