With Context Manager in Python

With Context Manager in Python

With Context Manager in Python In this Article i will show you how to use the “with” Keyword to create a text file and then write something into the File

Sample Code

  1. Using the  “with ” Keyword “
  2. Open and create a new file called  ” Sample.txt” and then assign “w” to write something into the File
  3. Use the Write Function “write() ” and then write text or  number you want into the file you ave just created

 


with open("sample.txt","w") as myfile:
    myfile.write('Hi There')


Results

Check out Multiple iteration in Python here

Leave a Reply

Your email address will not be published. Required fields are marked *

10 − seven =