top of page
Writer's pictureRosario Riley

Python Tuple Example

Python is a programming language which works quickly and integrates systems more effectively in development process.


Python is a multi-paradigm programming language: object-oriented programming and structured programming.


The Python syntax (words and structure) is extremely simple to read and follow, most of which can be understood even if you do not know any programming.





Example:-


print('Hello Python')


Output:-


Hello Python



Tuple Data Type


In Python the tuple data type is defined as an ordered collection of Python objects. The main difference between tuple and list is that tuples are immutable i.e. tuples can’t be modified after it’s created. It is represented by tuple class. In Python the we can represent tuples using parentheses ( ).


Example:

my_tuple = ("Apple", "Mango", "Banana")

print(my_tuple)

Output:-

('Apple', 'Mango', 'Banana')


v Tuple Items


Tuple items formats are ordered, unchangeable, and allow duplicate values while execution.

Tuple items are indexed based, the first item starts from index [0] and the second item index [1] etc.


v Ordered


Tuple items formats are ordered, it means that the each items have a defined order, and that order will not change during the flow of program.


v Unchangeable


Tuples values are unchangeable, which means that alteration is not possible once created we cannot change, add or remove items after the tuple has been created.


v Allow Duplicates


Tuples are indexed based; they can have items with the same value as per flow of program:


Example:

my_tuple = ("Apple", "Mango", "Banana", "Apple", "Banana")

print(my_tuple)

Output:-

('Apple', 'Mango', 'Banana', 'Apple', 'Banana')


v Tuple Length


To determine that how many items a tuple has, use the len() function:



Example:

my_tuple = ("Apple", "Mango", "Banana", "Apple", "Banana")

print(len(my_tuple))

Output:-

5


TCCI provides best teaching in Python programing language through different learning method/media as per students convince.


For More Information:

Call us @ 9825618292

Visit us @ http://tccicomputercoaching.com

Recent Posts

See All

Comments


bottom of page