How to use all tuple methods in Python

1 Answer

0 votes
tpl = ("python", "php", "java", "c++", "php")

print("1.", tpl[1], "\n")

for item in tpl:
    print(item)
print("\n")

if "python" in tpl:
    print("3.", "Yes")

print("4.", len(tpl))

print("5.", tpl.count("php"))

print("6.", tpl.index("c++"))

del tpl
# print("7.", tpl)  # Error: name 'tpl' is not defined


'''
run:
 
1. php

python
php
java
c++
php


3. Yes
4. 5
5. 2
6. 3

'''

 



answered Nov 22, 2018 by avibootz

Related questions

1 answer 119 views
1 answer 119 views
119 views asked Oct 17, 2023 by avibootz
1 answer 134 views
1 answer 139 views
139 views asked Nov 22, 2018 by avibootz
1 answer 158 views
158 views asked Nov 22, 2018 by avibootz
...