Python write to file

I have created a function and I want to print its output to a file. But when I use the write method, it says you need to write a string. It’s type return none. What should I do?
(When I call the function, the output text in the console)

To write a number in the file, first make it a string type: str(123) .

the output of the function was not a number or a string, it was just what I printed with the print function

actually i tried to print inside the function it was then but i can not removing some quotes now

outputs are like this: 34, ‘+’, 56, ‘=’, 90

Is the function none returned? :thinking:

no just type returns none
class

If the function returns nothing or returns None, you should write in the function, such as “return hello”.

1 Like

Can’t I just say print(“hello”) do i have to use return

1 Like

then you can’t print the function, write requires a string

1 Like

print() just displays output in the console. As such, print() itself is a function that returns None.

1 Like