Python Forum
How to avoid "None"s in the output - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to avoid "None"s in the output (/thread-10782.html)



How to avoid "None"s in the output - sylas - Jun-06-2018

Hi all. I don't know from where "None" come. Of course I should like to get rid of them.
class FirstClass:
	def setdata(self, value):
		self.data=value		
	def display(self):
		print(self.data)
		
x=FirstClass()
y=FirstClass()
x.setdata("King Arthur")
y.setdata(3.14159)
print(x.display())     #King Arthur
print(y.display())     #3.14159
x.data="Age of King Arthur"
print(x.display())     #Age of King Arthur
x.anotherInteger=67
print(x.anotherInteger)   # 67
And now the Output
Output:
λ python class1.py King Arthur None 3.14159 None Age of King Arthur None 67



RE: How to avoid "None"s in the output - buran - Jun-06-2018

You get None printed because FirstClass.display function does not return anything so it does return the default None.
In your code you print from within the function, so there is no need to print again when calling the function, e.g.
replace print(x.display()) with just x.display()