Python Tuple In Hindi In Python Programming
Python Tuple In Hindi Introduction: Python Programming In Hindi me aapka swagat hai! Aaj hum Python tuple ke baare mein detail mein baat karenge. Python tuple bhi list ki tarah hi built-in data type hai jo ki data collections ko store karne ke liye use hota hai. Python mein tuple ordered aur unchangeable hota hai, aur ye duplicates ko bhi allow karta hai.
Python Tuple In Hindi | Python Programming In Hindi |
1. Python Tuple Kya Hai?
Python tuple ek ordered collection hai jo unchangeable hota hai. Matlab, ek baar tuple banane ke baad aap uske elements ko change nahi kar sakte. Iska syntax simple hai aur tuples ko hum parentheses () use karke banate hain.
यह भी पढ़ें: 250+ Free Python Projects with Source Code: From Beginner to Advanced
Example:
t = (12, 45, 67, 8990, 78)
print(t)
2. Python Tuple Ki Properties
Python tuple ki kuch khas properties hoti hain jo ise unique banati hain:
Ordered
Tuple ordered hota hai. Matlab jis order mein aap items ko tuple mein insert karte hain, waisa hi order maintain hota hai.
Example Python code:
t = (12, 45, 67, 8990, 78)
print(t[0]) # Output: 12
print(t[2]) # Output: 67
print(t[4]) # Output: 78
Unchangeable
Python tuple unchangeable hota hai. Matlab ek baar tuple create ho gaya, to aap uske items ko add, remove ya update nahi kar sakte.
Duplicate Values Allowed
Tuple mein duplicate values allow hoti hain. Aap same item ko multiple times insert kar sakte hain.
Example Python code:
t = (12, 45, 12, 78, 45)
print(t) # Output: (12, 45, 12, 78, 45)
3. Python Tuple Banane Ka Tarika
Tuple banane ke liye aapko parentheses () use karna hota hai.
Example Python code
t = (1, 2, 3, 4, 5)
Ye bhi yaad rakhe ki agar aap single element ka tuple banate hain, to aapko uske baad comma , lagana zaroori hai.
Example Python code:
t = (1,)
print(type(t))
# Output: <class 'tuple'>
Agar aap comma nahi lagate, to ye tuple nahi banega.
Example Python code:
t = (1)
print(type(t))
# Output: <class 'int'>
4. Python Tuple Ka Use
Tuple ka use tab hota hai jab aapko ek ordered collection store karna ho jo immutable ho. Yani jise change na kiya ja sake. Ye mostly tab use hota hai jab aapko read-only data store karna ho.
Example python code:
months = ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
5. Python Tuple Ka Type Aur Length
Tuple ka type aur length jaanne ke liye type() aur len() function ka use hota hai.
Example Python code:
t = ("name", 34, 56.78, True)
print('Type:', type(t)) # Output: <class 'tuple'>
print('Length:', len(t)) # Output: 4
6. Python Tuple Mein Single Element
Jaise ki pehle bataya gaya, agar tuple mein sirf ek hi element hai, to aapko uske baad comma lagana zaroori hai. Warna wo tuple nahi banega.
Example Python code:
t1 = (12)
print(type(t1))
# Output: <class 'int'>
t2 = ('Rahul')
print(type(t2))
# Output: <class 'str'>
t3 = (True)
print(type(t3))
# Output: <class 'bool'>
t4 = (5.6)
print(type(t4))
# Output: <class 'float'>
7. Python Tuple Ko Iterate Karna
Tuple ko aap for loop ya while loop ki madad se iterate kar sakte hain.
Example python code:
t = ("name", 34, 56.78, True)
print('Iterate using for loop:')
for item in t:
print(item)
print('\nNow iterate using while loop:')
no = 0
while no < len(t):
print(t[no])
no += 1
8. Python Tuple Ko Access Karna
Tuple ke items ko index number se access kiya ja sakta hai. Aap colon : ka use karke bhi ek particular part access kar sakte hain.
Example python code:
tuple_var = (12, 45, 56, 5, 76, 78, 78, 45, 12)
print(tuple_var[4]) # Output: 76
print(tuple_var[2:]) # Output: (56, 5, 76, 78, 78, 45, 12)
print(tuple_var[4:6]) # Output: (76, 78)
print(tuple_var[:5]) # Output: (12, 45, 56, 5, 76)
print(tuple_var[-1]) # Output: 12
print(tuple_var[3:-1]) # Output: (5, 76, 78, 78, 45)
print(tuple_var[-8:-1]) # Output: (45, 56, 5, 76, 78, 78, 45)
9. Python Tuple Ka Real-world Examples
Example 1: Coordinates Store Karna
Tuple ka use coordinates store karne ke liye bhi hota hai, jaha aapko x aur y values ko pair mein store karna hota hai.
Python code:
coordinate = (10, 20)
print('X:', coordinate[0])
print('Y:', coordinate[1])
Example 2: Database Records
Database records ko immutable rakhne ke liye bhi tuple ka use hota hai.
Python code:
record = ("Rahul", "Kumar", 25, "Engineer")
print('Name:', record[0] + " " + record[1])
print('Age:', record[2])
print('Profession:', record[3])
Example 3: Configuration Settings
Configuration settings ko tuple mein store karna safe hota hai kyunki ye change nahi hoti hain.
Python code:
config = ("localhost", 8080, "root", "password")
print('Host:', config[0])
print('Port:', config[1])
print('User:', config[2])
print('Password:', config[3])
Conclusion: Python Tuple In Hindi
Aasha hai ki aapko Python tuple ke baare mein achi tarah se samajh aa gaya hoga. Python tuple ek ordered aur unchangeable collection hota hai jo duplicates ko allow karta hai. Iska use mostly tab hota hai jab hume data ko immutable rakhna hota hai. Tuple ka syntax simple hai aur iske items ko access karna ya iterate karna bhi bahut easy hai.
Aap Python Programming In Hindi seekhne ke liye hamare blog ko follow karte rahein aur naye updates ke liye subscribe karein. Python tuple ke aur bhi examples aur use cases ke liye comments mein likhe, hum aapki madad karenge.
Aapko ye article "Python Tuple In Hindi" pasand aya ho to please share karein aur apne doston ko bhi batayein. Python Programming In Hindi seekhna bahut asaan aur mazedaar hai. Keep learning and keep growing!
यह भी पढ़ें: Python Programming In Hindi | Python Tutorials In Hindi