unsupported operand type(s) python v2.7

ngangsia akumbo ngangsia at gmail.com
Tue Oct 20 05:13:46 EDT 2015


On Tuesday, October 20, 2015 at 10:08:51 AM UTC+1, ngangsia akumbo wrote:
> On Tuesday, October 20, 2015 at 10:01:44 AM UTC+1, Wolfgang Maier wrote:
> > On 20.10.2015 10:44, ngangsia akumbo wrote:
> > >>>> def n():
> > > 	34 * 2
> > >
> > > 	
> > >>>> def g():
> > > 	4 + 2
> > >
> > 
> > Your n and g functions do not have an explicit return so, after doing 
> > their calculations and throwing the result away, they return None.
> > 
> > >>>> def ng():
> > > 	return n() + g()
> > >
> > >>>> ng()
> > >
> > > Traceback (most recent call last):
> > >    File "<pyshell#14>", line 1, in <module>
> > >      ng()
> > >    File "<pyshell#13>", line 2, in ng
> > >      return n() + g()
> > > TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
> > >
> > 
> > The attempt in ng to add None to None then produce the exception you are 
> > seeing.
> 
> thanks


def n():
    return 3 * 2

def g():
    return 3+ 6

def ng():
    return n()+g()

print ng()



More information about the Python-list mailing list