Important Notice:

Tuple

Tuple

3 views 2 min read

Tuple in Python (टपल) :-

Tuple (टपल) Python का एक Built-in Data Type है, जिसका उपयोग एक या अधिक (One or More) Values को एक ही Variable में Store करने के लिए किया जाता है।

Tuple में समान (Same Type) तथा भिन्न-भिन्न (Different Types) के Data को एक साथ Store किया जा सकता है।

Tuple एक Ordered (क्रमबद्ध) तथा Immutable (अपरिवर्तनीय) Data Structure है। इसका अर्थ है कि Tuple बनने के बाद उसके Elements को बदला (Modify), जोड़ा (Add) या हटाया (Remove) नहीं जा सकता।

Python में Tuple को Parentheses () के अंदर लिखा जाता है तथा प्रत्येक Element को Comma (,) से अलग किया जाता है।

   महत्वपूर्ण: Tuple का उपयोग तब किया जाता है जब Data को बदलना नहीं हो।

Syntax -

tuple_name = (item1, item2, item3, ...)

Example-

numbers = (10, 20, 30, 40)

print(numbers)
 
Output -
(10, 20, 30, 40)
 
Note- Single Element Tuple (एक Element वाला Tuple) -

यदि Tuple में केवल एक Element हो, तो उसके बाद Comma (,) लगाना आवश्यक है, अन्यथा Python उसे Tuple नहीं मानेगा।

If a Tuple contains only one element, a comma (,) must be added after the element; otherwise, Python treats it as a normal value.

Example-
 
a = (10,)
print(type(a))
 
Output-
<class 'tuple'>
 
Empty Tuple (खाली Tuple) -
 
empty_tuple = ()

print(empty_tuple)
 
Output -
()
 
 English-

A Tuple is a Built-in Data Type in Python used to store one or more values in a single variable.

A Tuple can store same as well as different types of data together.

A Tuple is an ordered and immutable data structure. This means that once a Tuple is created, its elements cannot be modified, added, or removed.

In Python, a Tuple is written inside parentheses (), and each element is separated by a comma (,).

    Important: Tuples are used when the stored data should not be changed.

Syntax -

tuple_name = (item1, item2, item3, ...)

Example-

numbers = (10, 20, 30, 40)

print(numbers)
 
Output -
(10, 20, 30, 40)
 
 
Note- Single Element Tuple (एक Element वाला Tuple) -

यदि Tuple में केवल एक Element हो, तो उसके बाद Comma (,) लगाना आवश्यक है, अन्यथा Python उसे Tuple नहीं मानेगा।

If a Tuple contains only one element, a comma (,) must be added after the element; otherwise, Python treats it as a normal value.

Example-
 
a = (10,)
print(type(a))
 
Output-
<class 'tuple'>
 
Empty Tuple (खाली Tuple) -
 
empty_tuple = ()

print(empty_tuple)
 
Output -
()

Related Notes