python - How to append function to a list then print it -
i creating basic recipe viewer in python, stumbled across problem of when try print saved recipe displays [none]
, seen recipe firstly function, appended onto list try print when loading it.
the code below can explain more. how stop [none, none]
appearing? code below sample made adapt resolving issue in recipe rather posting entire code on here.
b = [] #this meant resemble list def function(): # meant resemble recipe print("hi") function() = input('write 1 = ') # meant resemble user saving recipe if == '1': b.append(function()) # meant resemble me saving recipe onto list print(b) # meant resemble me loading recipe
when run code , sorry don't have enough reputation points post image comes in python shell
hi write '1' = 1 #user input hi [none]
you not returning function. printing, that's not same thing.
use return
return value:
def function(): return "hi"
print()
writes terminal, caller of function not given output.
you can use print()
print return value:
print(function())
Comments
Post a Comment