WEB DEVELOPER SITE
PHP7
 

Python -Triples


Triples are generally sequences list.Triple can't change list


Tuple

Example 1

thistuple = ("Vegetables ", "Fruit", "Lean ")
print(thistuple)
Result Answer: ('Vegetable', 'Fruit', 'Lean')

Example 2


thistuple = ("Vegetables ", "Fruit", "Lean ")

print(thistuple[2])
Result Answer: ('Fruit')

Example 3

thistuple = ("Vegetables ", "Fruit", "Lean ")
thistuple[1] = "Milk" # test changeability


Result Answer: ('Vegetables', 'Fruit', 'Lean')

Indexing, Slicing, and Matrixes

L = ('welookups', 'Welookups', 'WELOOKUPS!')
Python expression Description Example
L[2] offset is start with zero 'WELOOKUPS!'
L[-2] Negative
L[1:] Slicing fetches sections ['Welookups', 'WELOOKUPS!']

tuple() Constructor

len() method returns the number of items

Example

thistuple = tuple(("Vegetables ", "Fruit", "Milk")) print(len(thistuple)) 3