How to write a string to a text file in Python
To write a string to text file, we can use the print()
method in python.
Here is an example, that writes the string data to amount.txt
file.
price = 33.3
your_data = {"Purchase Amount": price}
print(your_data, file=open('D:amount.txt', 'w'))
It opens the
amount.txt
file withyour_data
string.