xxxxxxxxxx
# Method 1
# Use context manager "with" that automatically closes connection
with open("filename.txt", "w") as file: # xyz.txt is filename, w means write format
file.write("hello") # write text xyz in the file
# Method 2
# Manually close connection
f= open("filename.txt", "w")
print(f.name) # will show what file is currently you are working with : filename.txt
print(f.mode) # will show which mode is currently in use : w
f.write("hello")
f.close()