Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I'm using Python to open a text document:

text_file = open("Output.txt", "w") 

text_file.write("Purchase Amount: " 'TotalAmount') text_file.close()

I want to substitute the value of a string variable TotalAmount into the text document. Can someone please let me know how to do this?

1 Answer

0 votes
by (106k points)

You can use the below-mentioned code to print a string to text file:-

with open("Output.txt", "w") as text_file: 

print("Purchase Amount: {}".format(TotalAmount),

 file=text_file)

Related questions

0 votes
1 answer
asked Jul 3, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
2 answers
asked Sep 12, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...