-2

Recently started learing Python.

I defined title and price.

Now I want Python to create a Text file and enter the content of "title" and "price" into the new created text file

print(title)
print(price)

fh = open("Price&Title", "w")
fh.write()
fh.close()

This code above didnt work.

khelwood
  • 52,115
  • 13
  • 74
  • 94

1 Answers1

0

You can use the file argument of print:

fh = open("Price&Title", "w")
print(title, file=fh)
print(price, file=fh)
fh.close()
enzo
  • 9,121
  • 2
  • 12
  • 36