Aug 31, 2010

Python functions

i = 5

def f(arg=i):
print arg

i = 8
f()

This will print 5. In this it will only assign a defaule value for one time.
def car(wheels,modle="toyota"):
print "No of wheels",wheels
print "Modle name : ",modle

car(4,modle="dimo")


More list methods
a=[2,333,333,45.4,] We will use this list for the following samples.
print a.count(333),a.count(2),a.count(99)
2 1 0
-
a.append(x)
this will add x to the end of "a" list.
-
a.extend(list)
add another list to list 'a'.
-
a.insert(index,value)
this will add a value to a given index.
-
a.remove(x)
this will remove the first x value.
-
a.pop()
this will remove & return the last value in the list
if it is like this;
a.pop(3)
it will remove the 4th value and return that value.
-
a.index(333)
this will give the index of the first 333 value in the array.
-
a.sort()
this will sort the array
-
a.reverse()
this will revers te array

List as stacks
pop() - to pop
append() - to push

No comments:

Post a Comment

Your comments are always welcome ...