Tuple in Python is more or less like list but with one very important difference i.e tuple is not modifiable or editable. That means once declared you can't change the value of a tuple.
To declare a tuple just like
>> a=() or
>>a=tuple()
The above two will create an empty tuple.
You can write like below to create a tuple with value.
To declare a tuple just like
>> a=() or
>>a=tuple()
The above two will create an empty tuple.
You can write like below to create a tuple with value.
>>a=(2,1,35,3,7,3)
>>a
(2,1,35,3,7,3)
>>a
(2,1,35,3,7,3)
The insert, remove, push, pop these commands will not work in tuple as worked in a list.
We can count the number of occurrence of an element by count method
We can count the number of occurrence of an element by count method
>>a.count(3)
2
2
Also we can find the first occurrence of any element by index method.
>>a.index(3)
3
3
We will discuss more about tuple when we will use it in real program.
No comments:
Post a Comment