Answers for "Write a python program to create a file (myfile.txt), write multiple types of data in it and print the content."

3

python write to file

with open("test.txt",'w',encoding = 'utf-8') as f:
   f.write("my first filen")
   f.write("This filenn")
   f.write("contains three linesn")
Posted by: Guest on October-16-2020
2

python write to file

# using 'with' block

with open("xyz.txt", "w") as file: # xyz.txt is filename, w means write format
  file.write("xyz") # write text xyz in the file
  
# maunal opening and closing

f= open("xyz.txt", "w")
f.write("hello")
f.close()

# Hope you had a nice little IO lesson
Posted by: Guest on November-02-2020

Code answers related to "Write a python program to create a file (myfile.txt), write multiple types of data in it and print the content."

Python Answers by Framework

Browse Popular Code Answers by Language