Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print None
#1
Why i am getting none here ?--- this is because it is treat as two statement
how to avoid it ?
or how to concord it in a single line?

C:\Users>python
Python 3.4.4 (v3.4.4 Dec 20 2015, 20:20:57) 
Type "help", "copyright", "credits" or "license" for more information.
>>> length = 1.10
>>> width  = 2.20
>>> area   = length * width
>>> print ("The area is: ") , area
The area is:
(None, 2.4200000000000004)
>>>
Reply
#2
You need:
print ("The area is: ", area)
Putting a comma and an object behind the print function you are creating a tuple. The print function returns None. It's like:
>>> var = print('Hello!')
Hello!
>>> area = 300
>>> var, area
(None, 300)
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
Actually you print just print ("The area is: ") . The result is what you see on line#8
Because print function returns None on line #7 you get two-element tuple and that is what you see on line #9
print ("The area is: {}".format(area))
would print everything on one line, but because you are in the interactive mode you will still get the None on the next line
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
Thanks !
My pyodbc returns cursor result as below
>>> result
[(Decimal('28000.0000'), 2010, 272), (Decimal('308000.0000'), 2011, 272), (Decimal('582000.0000'), 2012, 272), (Decimal('387000.0000'), 2013, 272), (Decimal('367000.0000'), 2010, 281), (Decimal('3037000.0000'), 2011, 281), (Decimal('4822000.0000'), 2012, 281), (Decimal('2936000.0000'), 2013, 281), (Decimal('637000.0000'), 2010, 282), (Decimal('3440000.0000'), 2011, 282), (Decimal('4415000.0000'), 2012, 282), (Decimal('3294000.0000'), 2013, 282), (Decimal('478000.0000'), 2012, 296), (Decimal('1209000.0000'), 2013, 296)]
>>>
how to get data in list as below
Salesamount should split based on the year.
Salesamount = [[28000.00,308000.00,582000.00,387000.00],[367000.00,3037000.00,4822000.00,2936000.00],[637000.00,3440000.00,4415000.00,3294000.00],[0,0,478000.00,1209000.00]]
CalendarYear = [2010,2011,2012,2013]
Employee = [272,281,282,296]
In Salesamount 0,0 needs to be added for 296th record as it has only value for 2012 and 2013 , so we need to add 0 for 2011 and 0 for 2012
Also how to remove decimal as it is displaying as decimal in the list

>>> type(result)
<class 'list'>
Thanks
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020