Python Tuples Example

Chapter: Python Last Updated: 19-11-2021 15:58:05 UTC

Program:

            /* ............... START ............... */
                
tupleExample = ("Mathew", "John", "James")
print(tupleExample)
print(len(tupleExample))
/*
('Mathew', 'John', 'James')
3
*/


tuple1 = ("apple", "banana", "cherry")
tuple2 = (1, 5, 7, 9, 3)
tuple3 = (True, False, False)

print(tuple1)
print(tuple2)
print(tuple3)
/*

('apple', 'banana', 'cherry')
(1, 5, 7, 9, 3)
(True, False, False)
*/

tuple1 = ("abc", 34, True, 40, "male")

print(tuple1)

/*
('abc', 34, True, 40, 'male')
*/
                /* ............... END ............... */
        

Notes:

  • Python Tuples are used to store multiple items in single variable. In above program tupleExample is holding three string items.
  • Tuples is built in data type in pyton to store collections of data. A tuple is a collection which is ordered and unchangeable.
  • Python tuples are written in round backeets (eg : tuple1 = ("apple", "banana", "cherry")).
  • Tuple items are indexed, the first item has index [0], the second item has index [1] etc.
  • Tuple is with order and that cannnot be change.
  • Tuples are unchangeable, so that we cannot change, add or remove items after the tuple has been created.
  • Python tuple can store duplicate values, so there can have same value items.
  • len() function python will the size of tuple. First program shows how to find the legnth of tuple.
  • Tuple can store the items of different data types (eg: tuple1 = ("abc", 34, True, 40, "male")), in this you can see that it is storing string, boolean and numbers.
Similar Programs Chapter Last Updated
Python Program To Check Whether Element Present In Set Or Not Example Python 04-10-2023
Python Program To Find Maximum And Minimum Number In A Set Python 04-10-2023
Python Program To Check Symmetric Matrix Python 04-10-2023
Python Program To Find Subsets Of A Set Python 04-10-2023
Python Program To Find Power Set Of A Set Python 04-10-2023
Remove All Duplicates From List Python Python 04-10-2023
Python Program To Find Symmetric Difference Of Two Sets Python 27-09-2023
Python Program To Find Common Item From Two Set Python 27-09-2023
Python Program To Get Unique Values From A List Python 27-09-2023
Python Encode And Decode String With Key Python 24-09-2023
Python Simple Encrypt Decrypt String Python 24-09-2023
Python Format String To Specific Length Python 24-09-2023
Python Code To Check If String Contains Substring Python 24-09-2023
Python Program To Find Most Repeated Word In A String Python 23-09-2023
Split String Into Words Python Python 23-09-2023
Remove All Punctuation Python Python 23-09-2023
Python Program To Reverse An Array Python 23-09-2023
Python Program To Find Number Of Palindrome In A String Python 23-09-2023
Python Program To Find Longest Common Substring Python 23-09-2023
Python Program To Find Number Of Days In A Given Month And Year Python 22-09-2023
Python Program To Calculate Age Of A Person Python 22-09-2023
Python Code To Get Day Of Week Python 22-09-2023
Python Convert String To Date Without Time Python 22-09-2023
Python Program To Print Current Date And Time In Format dd/mm/yyyy Python 22-09-2023
Python Program To Find Working Days In A Month Python 19-09-2023
Python Code To Change Date Format Python 16-09-2023
Python Program To Calculate Number Of Days Between Two Dates Python 16-09-2023
Python Program To Calculate Age In Years Months And Days Python 16-09-2023
Python Program To Schedule A Job To Run After A Certain Amount Of Time Python 10-08-2023
Python Program To Schedule A Job To Run Randomly Once A Day Python 10-08-2023

1 2 3 4