B.Tech Students: Apply for Live Programming Internship C, C++, Java, Python ,Web page Designing, PHP Python Tuple Methods with Examples | LiveCodeProgramming

Python Tuple Methods

Tuples have only two built-in methods: count() and index(). Tuples are immutable, so no method can change their content.

Tuple में सिर्फ दो built-in methods होते हैं: count() और index()। Tuple immutable होता है, इसलिए इसे modify करने वाला कोई method नहीं होता।

1. count()

Returns how many times an item appears in the tuple.

Tuple में कोई value कितनी बार repeat हुई है, यह return करता है।

names = ("Aryan", "Abhishek", "Aryan", "Jayati", "Aryan")
print(names.count("Aryan"))
Output:
3
2. index()

Returns the index of the first matching value.

Tuple में कोई value सबसे पहले कहाँ है, उसका index return करता है।

students = ("Chaitanya", "Naincy", "Shrutika", "Jayati")
print(students.index("Shrutika"))
Output:
2