Monday, June 29, 2015

Python list

Python has a versatile component list. Some author of Python books named it as arrays on steroid! Funny though, the necessities and implications of list in Python is huge.
A list can be declared within third brackets and comas separating entities. e.g.
>>a=[10,15,20,22,2]
Here a list 'a' is created with five values in it. Python automatically determines the data type odd the values within. The above list is a list of integers, we can make list of floats in a same way. We can also make a mixed list.
>>b=[10,'lucky',3.5,27,”11”]
Here you can see a list with a mixture of data types.
We can sort, append, reverse, delete and insert element into list. I.e. items of a list can be altered and modified without any problem.
Some list operations -
>>a=[ ]
#for declaration of an empty list
>>a.append(4)
#to append 4 in the empty list
>>a.insert(7,2)
#to insert 7 in the list in the second position. Now a =[4,7]
>>a[0]=4
#as the index start with zero, so index of the first element is zero.
>>a.sort()
#to sort the element of a
>>a.remove(4)
#to remove 4 from list
Please see dir(a) or dir (list) for all the information about list. Try all the operations you can do with list. I will cover/use list throughout this blog, so no problem of I skip something about list now.
Here is the basic list option video, please bear with me as this video is by screencast by using qpython, android Python.

No comments:

Post a Comment

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...