Step 1
Open any text editor (gedit,pico,vi,nano) then enter the following python script and save the file with .py extension.
#!/usr/bin/python
#Author : Jijo K Jose
print "\n------------------------------------\nChapter 7 - List\n------------------------------------\n"
l1 = [1,2,3,4]
l2 = [5,6,7,8]
print "List Manipulations L1 : " ,l1
print "List Manipulations L2 : " ,l2
l1.reverse()
print "\nList reverse : ", l1
l1.append(l2)
print "\nList append (Create multi diamension list) : ", l1
print "\nElement [4][2] is : ", l1[4][2]
l1 = [1,2,3,4];
l2 = [5,6,7,8];
l1.extend(l2)
print "\nList extend (Create single diamension list) : ", l1
l1.pop()
print "\nRemove last element from list -pop() : ",l1
l1.pop(2)
print "\nRemove 2nd element from list -pop(2) : ",l1
l1.insert(2,3)
print "\nInsert element into list -insert(,i,val) : ",l1
l3=range(5,27,2)
print "\nCreate a range of integers - range(init,end,step) : ",l3
print "\n------------------------------------\n"
#END
Step 2
Change file permission to executable using chmod command.
Step 3
Execute the python file.
No comments:
Post a Comment