A tuple is a collection in Python which is ordered and immutable. Tuples are written using parentheses ()
.
Tuple Python का एक collection है जो ordered और immutable होता है। इसे ()
में लिखा जाता है।
students = ("Abhishek", "Chaitanya", "Naincy", "Shrutika", "Jayati", "Aryan")
print(students)
Output:('Abhishek', 'Chaitanya', 'Naincy', 'Shrutika', 'Jayati', 'Aryan')
print(students[1])
Output:Chaitanya
for name in students:
print(name)
Output:Abhishek Chaitanya Naincy Shrutika Jayati Aryan
if "Aryan" in students:
print("Yes, Aryan is in the tuple")
Output:Yes, Aryan is in the tuple
print(len(students))
Output:6
single = ("Aryan",)
print(type(single))
Output:<class 'tuple'>
group1 = ("Abhishek", "Jayati")
group2 = ("Naincy", "Shrutika")
combined = group1 + group2
print(combined)
Output:('Abhishek', 'Jayati', 'Naincy', 'Shrutika')
print(students[1:4])
Output:('Chaitanya', 'Naincy', 'Shrutika')