Lesson - 18 : Python3 - Python Variables : Tuple

Published: 17 December 2017
on channel: Sada Learning Hub
66
2

**************************************************
Python Core PlayList :    • Lesson - 01 : Python3 - What is python  
Python Advanced PlayList :    • Lesson - 46 : Python Advanced - Pytho...  
**************************************************
Python DataType : Tuple:
A tuple is a container which holds a series of comma-separated values (items or elements) between parentheses. Tuples are immutable (i.e. you cannot change its content once created) and can hold mix data types.

Tuples are a group of values like a list and are manipulated in similar ways. But, tuples are fixed in size once they are assigned. In Python the fixed size is considered immutable as compared to a list that is dynamic and mutable. Tuples are defined by parenthesis ().
myGroup = ('Rhino', 'Grasshopper', 'Flamingo', 'Bongo')

Here are some advantages of tuples over lists:
Elements to a tuple. Tuples have no append or extend method.
Elements cannot be removed from a tuple.
You can find elements in a tuple, since this doesn’t change the tuple.
You can also use the in operator to check if an element exists in the tuple.
Tuples are faster than lists. If you’re defining a constant set of values and all you’re ever going to do with it is iterate through it, use a tuple instead of a list.
It makes your code safer if you “write-protect” data that does not need to be changed.

Built-in Tuple Functions :
cmp(tuple1, tuple2) : Compares elements of both tuples.
len(tuple) : Gives the total length of the tuple.
max(tuple) : Returns item from the tuple with max value.
min(tuple) : Returns item from the tuple with min value.
tuple(seq) : Converts a list into tuple.

Sample Projects : https://github.com/SadaLearningHub1/P...


On this page of the site you can watch the video online Lesson - 18 : Python3 - Python Variables : Tuple with a duration of hours minute second in good quality, which was uploaded by the user Sada Learning Hub 17 December 2017, share the link with friends and acquaintances, this video has already been watched 66 times on youtube and it was liked by 2 viewers. Enjoy your viewing!