[Tutor] help

George Nyoro geonyoro at gmail.com
Mon Oct 10 21:23:11 CEST 2011


On 10/10/2011, tutor-request at python.org <tutor-request at python.org> wrote:
> Send Tutor mailing list submissions to
> 	tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> 	tutor-request at python.org
>
> You can reach the person managing the list at
> 	tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>    1. I am trying to print list elements but i am getting 'none'
>       (Praveen Singh)
>    2. Re: I am trying to print list elements but i am getting
>       'none' (Nitin Pawar)
>    3. Re: I am trying to print list elements but i am getting
>       'none' (Christian Witts)
>    4. Re: I am trying to print list elements but i am getting
>       'none' (Steven D'Aprano)
>    5. Re: I am trying to print list elements but i am getting
>       'none' (Wayne Werner)
>    6. Re: I am trying to print list elements but i am getting
>       'none' (Bod Soutar)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 10 Oct 2011 09:26:31 -0400
> From: Praveen Singh <c2praveen30jun at gmail.com>
> To: tutor at python.org
> Subject: [Tutor] I am trying to print list elements but i am getting
> 	'none'
> Message-ID:
> 	<CAJcoizvqvGot=i_o6viURrWjH-FzAsxo456aURVS49sGmEBExw at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> 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-
>>>> myList=[]
>>>> myList.append(8)
>>>> print myList
> [8]
>
> Confused!!!
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> <http://mail.python.org/pipermail/tutor/attachments/20111010/2b4c9180/attachment-0001.html>
>
> ------------------------------
>
> Message: 2
> Date: Mon, 10 Oct 2011 19:00:40 +0530
> From: Nitin Pawar <nitinpawar432 at gmail.com>
> To: Praveen Singh <c2praveen30jun at gmail.com>
> Cc: tutor at python.org
> Subject: Re: [Tutor] I am trying to print list elements but i am
> 	getting	'none'
> Message-ID:
> 	<CAORpBsi3nfkYegcUpVcxw4Zp3FQ-kV0uJzpyZHxaj816E4Xj_w at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Try giving the print statement outside the for loop
>
> On Mon, Oct 10, 2011 at 6:56 PM, Praveen Singh
> <c2praveen30jun at gmail.com>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-
>> >>> myList=[]
>> >>> myList.append(8)
>> >>> print myList
>> [8]
>>
>> Confused!!!
>>
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
> --
> Nitin Pawar
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> <http://mail.python.org/pipermail/tutor/attachments/20111010/9801d714/attachment-0001.html>
>
> ------------------------------
>
> Message: 3
> Date: Mon, 10 Oct 2011 15:32:28 +0200
> From: Christian Witts <cwitts at compuscan.co.za>
> To: Praveen Singh <c2praveen30jun at gmail.com>
> Cc: tutor at python.org
> Subject: Re: [Tutor] I am trying to print list elements but i am
> 	getting	'none'
> Message-ID: <4E92F3EC.8080003 at compuscan.co.za>
> Content-Type: text/plain; charset="windows-1252"; Format="flowed"
>
> On 2011/10/10 03:26 PM, 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-
>> >>> myList=[]
>> >>> myList.append(8)
>> >>> print myList
>> [8]
>>
>> Confused!!!
>>
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>
> If you seperate your print and the myList.append operation you will get
> what you want, which is why it works in IDLE.  Are you sure you don't
> want to rather build your list, and return it from your function and
> then when you call it you do `print getNumbers(10)` if you wish.
>
> --
>
> Christian Witts
> Python Developer
>
> //
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> <http://mail.python.org/pipermail/tutor/attachments/20111010/f3c7b2f3/attachment-0001.html>
>
> ------------------------------
>
> Message: 4
> Date: Tue, 11 Oct 2011 00:51:36 +1100
> From: Steven D'Aprano <steve at pearwood.info>
> To: tutor at python.org
> Subject: Re: [Tutor] I am trying to print list elements but i am
> 	getting	'none'
> Message-ID: <4E92F868.8060407 at pearwood.info>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> 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
>
>
>
> ------------------------------
>
> Message: 5
> Date: Mon, 10 Oct 2011 09:14:01 -0500
> From: Wayne Werner <waynejwerner at gmail.com>
> To: Praveen Singh <c2praveen30jun at gmail.com>
> Cc: tutor at python.org
> Subject: Re: [Tutor] I am trying to print list elements but i am
> 	getting	'none'
> Message-ID:
> 	<CAPM86Nf-s_5bH-doo3F9MYts22guwZ0zrL6RjiEp9aYfQkgJSQ at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> On Mon, Oct 10, 2011 at 8:26 AM, Praveen Singh
> <c2praveen30jun at gmail.com>wrote:
>
>> print myList.append(numbers)
>
>
> Your problem is with that statement.
>
>>>> mylist = []
>>>> x = mylist.append(3)
>>>> x
>>>> x is None
> True
>>>> help(mylist.append)
> Help on built-in function append:
>
> append(...)
>     L.append(object) -- append object to end
>
>
> append returns None (all functions do, unless you explicitly return
> something that is not None)
>
> HTH,
> Wayne
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> <http://mail.python.org/pipermail/tutor/attachments/20111010/7417d006/attachment-0001.html>
>
> ------------------------------
>
> Message: 6
> Date: Mon, 10 Oct 2011 17:52:00 +0100
> From: Bod Soutar <bodsda at googlemail.com>
> To: Praveen Singh <c2praveen30jun at gmail.com>
> Cc: tutor at python.org
> Subject: Re: [Tutor] I am trying to print list elements but i am
> 	getting	'none'
> Message-ID:
> 	<CAG6Bxkc-PP4zQA80bqwHO5wu8ePYf2Am_OBk_ASFRW1umF8vTw at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On 10 October 2011 14:26, Praveen Singh <c2praveen30jun at gmail.com> 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-
>>>>> myList=[]
>>>>> myList.append(8)
>>>>> print myList
>> [8]
>>
>> Confused!!!
>>
>>
>>
>> _______________________________________________
>> Tutor maillist ?- ?Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
> Print your list after you have appended to it.
>
>  def getNumbers(num):
>     myList=[]
>     for numbers in range(0,num,2):
>           myList.append(numbers)
>
>     for item in list:
>         print item
>
>
> ------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> End of Tutor Digest, Vol 92, Issue 54
> *************************************
>


More information about the Tutor mailing list