Python Tuples
Tuple
This data structure of python is immutable like array. We can't update it after initialization.
Tuple is initialized using tuple class or ().
tuple1 = tuple()
tuple2 = ()
tuple3 = value1, value2,...,valueN
Below are some methods of tuple object
tuple.count(value)
Returns number of time value appears in tuple.tuple.index(value, [start, [stop]])
Returns first index of value or raises ValueError if value not present. It optionally take two more parameters start and stop and searches value in between start and stop.Lets Understand this by taking Example
>>> t=tuple() >>> t () >>> t = (19, 3, 7, 5, 2, 8) >>> t (19, 3, 7, 5, 2, 8) >>> 19 in t True >>> t[3:5] (5, 2) >>> len(t) 6 >>> t.count(3) 1 >>> t.index(3) 1
Keep Following, For More.
Is it, so less methods
ReplyDelete