PYTHON TUPLES IN HINDI

Python me Tuple kya hai?

Python me tuple ka use data ko ordered ways me store karne ka hota hai. Tuple me list ki tarah manipulations nhi kar sakte hai means python me tuple immutable hota hai jaha kuch bhi changes nhi kiya ja sakta hai.

Tuple ka Syntax:

tuple_data = (“america”“india”“japan”)
print(tuple_data)

Tuple me data ko single bracket “(…)” ke andar rakha jata hai, jaisa ki aap upar diye gaye example me dekh pa rahe hain.

Python me Tuple ko Tuple Constructor ka use karke bhi define kiya ja sakta hai.
Ex : tuple_data = tuple((“hello”, “Python”,2020))
       
print(tuple_data)

*** tuple(( … )) – Double parenthesis ka use start our end me use karna compulsory hota hai.

Tuple - Positive Indexing aur Negative Indexing

A Simple Example of Tuple : (Positive Indexing)

tuplevalue = (“america”, “india”, 2020)
print(tuplevalue)
type(tuplevalue)
type(tuplevalue[0])
type(tuplevalue[1])
type(tuplevalue[2])

Upar diya gaya example positive indexing ko signify kar raha hai, jaha  tuplevalue[0] , tuplevalue[1] , tuplevalue[2] ka use karke tuple ki values ko access kar pa rahe hain. 

Aur wahi Negative Indexing kuch aisa hi hai jaha hum kisi bhi index ko ‘ – ‘ sign ke sath use karke use access kar payenge. Samajhne ke liye niche diye gaye example ko dekhiye… 

A Simple Example of Tuple : (Negative Indexing)

tuplevalue = (“america”, “india”, 2020)
print(tuplevalue)
type(tuplevalue)
type(tuplevalue[-1])
type(tuplevalue[-2])
type(tuplevalue[-3])

Tuple - Positive Indexing aur Negative Indexing

tupleval=(“usa”,”india”,”England”,”Canada”,”Singapore”)
print(tupleval)
print(tupleval[:])
print(tupleval[0:])
print(tupleval[2:4])
print(tupleval[2:])
print(tupleval[-5:-2])
print(tupleval[0:6:1])

Example ko dekhkar aap samajh pa rahen honge ki hum kaise range of values ko access kar rahe hain. 
tupleval=(“usa”,”india”,”England”,”Canada”,”Singapore”)
                 [0]     [1]       [2]               [3]              [4]
                [-5]    [-4]      [-3]              [-2]             [-1]

tupleval[2:4] me ‘2’ start index aur ‘4’ end index hai. jisko run karne par aap uss bich ke range ki values ko dekh payenge.

Isi tarah tupleval[0:6:1] me ‘0’ start index aur ‘6’ end index hai lekin yaha ‘1’ ek step index hai jiska matlab yah hai ki output me aap 1 value skip kar rahen hain…means aap [0], [2],[4] index ki value dekh payenge.

Python Tuple me values kaise change karte hain?

Jaisa ki hum jante hain ki Tuple immutable hota hai jisme data ko manipulate nhi kiya ja sakta. Ab agar hum isme koi changes karna chahte hain to hume pahle isse list me convert karna hoga aur uske baad apne requirements ( list ki sari functionalities jaise – append(), extend(), remove() , pop() , clear() etc ) ke hisab se changes karke isse dubara tuple me convert karna hoga.

tupleval=(“usa”,”india”,”England”,”Canada”,”Singapore”)
convert_to_list = list(tupleval)
convert_to_list[4] = “Germany”
print(tupleval)
print(convert_to_list)
conver_to_tuple = tuple(convert_to_list) 

Tuple ki length calculate karen

tupleval=(“usa”,”india”,”England”,”Canada”,”Singapore”)
print(len(tupleval))

Kisi bhi tuple ki length len() function ka use karke nikali ja sakti hai.

Tuple me Looping ka concept

tupleval=(“usa”,”india”,”England”,”Canada”,”Singapore”)
for a in tupleval:
    print (a)

Python ke Tuple ke case me loop ka concept bilkul list jaisa hi hai. Jaisa example me show ho raha hai ki “for loop” automatically ‘a‘ ka starting index assign kar raha hai, jaha tuple 0th index se shuru ho raha hai. yah pahle 0th index ki value print karega aur backend me index ki value increment kar dega aur fir wah 1st index ki value print karega. Issi tarah list ke last index tak output execute hota jayega.

Single Data ke sath Tuple kaise create karen?

Agar hum chahte hai ki sirf ek single data ko lekar tuple create karen to hume uss data ko comma ke sath mention karna hoga. Comma ka use na karne par uski sari properties string ki hogi.

tuple_item1=(“usa”,)
print(type(tuple_item1))
tuple_item2=(“usa”)
print(type(tuple_item2))

Tuples ko aapas me kaise add kiya jata hai?

tupleval1=[“usa”,”india”,”England”,”Canada”]
tupleval2=[“Singapore”,”Belizium”]
tupleval3 = tupleval1 + tupleval2
print(tupleval3)

Python Tuple me 2 ya 2 se adhik tuples ko apas me jodne ke liye ‘+’ operator ka use kiya jata hai.

Tuples me use hone wale kuch important methods?

Python Tuple me mostly 2 tarah ke functions/methods use hote hain – Count(), Index(). Count function batayega ki koi ek value kitni baar iss tuple me use hui hai. Aur wahi index function search ki gai value ki indexing or index position ko print karega.

tupleval=(2, 34, 56, 26, 34, 56, 26, 389, 56)
b = tup4.count(26)
print(b)
c = tup4.index(34)
print(c)