Can convert with
str(z)
or better in many cases is to use string formatting f-string.with open('out.txt', 'w') as f: x = 5 y = 6 z = x + y f.write(f'Result is {z}')
Output:Result is 11