1. Use open() and close() To write :
# Save the file locally
# 1. Create a file
create_file = open("demo.txt", "w", encoding="utf-8")
# 2. Add saved content
data = "hello world"
# 3. Write the corresponding file
create_file.write(data)
# 4. Close file
create_file.close()
2. Use with Method write :
with open("1111.txt","w",encoding="utf-8") as f:
f.write("hello, world")
Above is python Common methods of saving files , There are better methods. Welcome to add .