Important Notice:

Creating a Tuple

Creating a Tuple

8 views 2 min read
Creating a Tuple :-

Python में Creating a Tuple का अर्थ है एक ऐसा Tuple बनाना जिसमें हम multiple elements या values को एक ही variable में store कर सकें। Tuple बनाने के लिए सामान्यतः parentheses ( ) का उपयोग किया जाता है और elements को comma (,) से separate किया जाता है।

English

Creating a Tuple means creating a collection in which multiple elements or values can be stored in a single variable. A Tuple is generally created using parentheses ( ), and its elements are separated by commas (,).

Syntax:-

tuple_name = (element1, element2, element3, ...)

Example:-

numbers = (10, 20, 30, 40, 50)

print(numbers)

Output:-

(10, 20, 30, 40, 50)

Because:-

यहाँ numbers एक Tuple है जिसमें पाँच elements हैं:

10, 20, 30, 40, 50

इन सभी values को numbers नाम के एक variable में store किया गया है।

English

Here, numbers is a Tuple containing five elements. All the values are stored in a single variable named numbers.

Creating a Tuple with Different Data Types :-

Tuple में different data types की values को एक साथ store किया जा सकता है।

Example:-

student = ("Rahul", 20, 85.5, True)

print(student)

Output:-

('Rahul', 20, 85.5, True)

Because:-

इस Tuple में:

"Rahul" → String
20 → Integer
85.5 → Float
True → Boolean

Creating an Empty Tuple :-

बिना किसी element के Tuple को Empty Tuple कहा जाता है।

Example:-

empty = ()

print(empty)

Output:-

()
 
Creating a Single-Element Tuple :-

यदि Tuple में केवल एक element हो, तो element के बाद comma , लगाना आवश्यक है।

Example:-

number = (10,)

print(number)
print(type(number))

Output:-

(10,)
<class 'tuple'>

Important Point :-

केवल parentheses लगाने से Single-Element Tuple नहीं बनता।

number = (10)

print(type(number))

Output:-

<class 'int'>

क्योंकि (10) को Python एक normal integer expression मानता है।

English

For a single-element tuple, a trailing comma is required.

Creating a Tuple Without Parentheses :-

Python में parentheses के बिना भी Tuple बनाया जा सकता है। इसे Tuple Packing कहा जाता है।

Example:-

numbers = 10, 20, 30

print(numbers)

Output:-

(10, 20, 30)

English

A tuple can also be created without parentheses. This is called Tuple Packing.

Important Points :-
 
Tuple elements को comma , से separate किया जाता है।
सामान्यतः Tuple को parentheses ( ) में लिखा जाता है।
Empty Tuple → ()
Single-element Tuple → (10,)
Tuple में different data types की values store की जा सकती हैं।
Tuple Immutable होता है।

Related Notes