how can I delet "None" in code output

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shahram555
    New Member
    • Aug 2014
    • 4

    how can I delet "None" in code output

    Code:
    >>class class1:
         name='civil'
         def printname(self,name):
             print self.name
             print name
    >>you=class1()
    >>you.mark=100
    >>print you.printname('shahram'),you.mark
    
      civil
      shahram
      None 100
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    Code:
    print you.printname('shahram'),you.mark
    prints the return from printname which is None. Try the following code
    Code:
    class class1:
         name='civil'
         def printname(self,name):
             print self.name
             print name
             print self.mark
             return "returned from printname"
    
    you=class1()
    you.mark=100
    print you.printname('shahram')
    So you have to return something you want to print, or eliminate the print statement. You might want to look at this tutorial on functions which includes return statements.

    Comment

    Working...