Showing posts with label portion tuple. Show all posts
Showing posts with label portion tuple. Show all posts

Tuesday, June 30, 2015

Python tuple

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.
>>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
>>a.count(3)
2
Also we can find the first occurrence of any element by index method.
>>a.index(3)
3
We will discuss more about tuple when we will use it in  real program.


Feautured Post

Python Trivia Post: enumerate()

Python has a very useful inbuilt function, which is called enumerate(). This is needed whenever you need the numbering of a certain element...