Data Type Of Python
In this session we will see last data type of python which is Tuple.
5) Tuple:- Tuple is a ordered collection of immutable datatype, tuples are quite similar to lists but difference is list are mutable where as tuple are immutable.
5) Tuple:- Tuple is a ordered collection of immutable datatype, tuples are quite similar to lists but difference is list are mutable where as tuple are immutable.
- Empty tuple:-
t = () or tuple() - Tuple with single element:-
t = (10,) - Tuple with multiple element:-
t1 = ( 10, 20, 30, 'Hello' ) - Nested tuple:-
t1 = ( 10, 20, 30, 'Hello' )
p = t2, 30, 40, 50
print(p) => ((10, 20, 30, 'Hello'), 30, 40, 50)
- count(value):- It return the count of value if the value is present in the tuple else it return 0.
For example:-
t = (10, 20, 30, 'Hello')
t.count(10) => 1
t.count(50) => 0 - index(value,start,end):- It return the index number if the value is present in the tuple, otherwise it raised value error.
For example:-
t = (10, 20, 30, 'Hello')
t.index(10) => 0
It return the index number of value 10.
Comments
Post a Comment