Praveen Singh wrote:
This is my code-
 def getNumbers(num):
    myList=[]
    for numbers in range(0,num,2):
          print myList.append(numbers)


output-
getNumbers(10)
None
None
None
None
None

Then i find out that list.append doesn't return anything.Then what should i
use for this kind of operation.but if i do something like this on idle's
interpreter it gives me answer-


If you want to print the list after each append, then print the list after each append:

def getNumbers(num):
    myList=[]
    for number in range(0, num, 2):
        myList.append(number)
        print mylist


If you want to print the list once, at the end, then print it once, at the end, *outside* the loop:

def getNumbers(num):
    myList=[]
    for number in range(0, num, 2):
        myList.append(number)
    print mylist


--
Steven

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to