In this Python Tutorial for Beginners video I am going to show you How to Create a Text File and Write in It Using Python . To open a file in Python we use open() function.open() returns a file object, and is most commonly used with two arguments: open(filename, mode).Before we can write to the file we must tell Python which file we are going to work with and what we will be doing with the file. This is done with the open() function. open() returns a “file handle” - a variable used to perform operations on the file
Kind of like “File - Open” in a Word Processor.
name = open("filename")- opens the given file for reading, and returns a file object
name.read() - file's entire contents as a string
name.readline() - next line from file as a string
name.readlines() - file's contents as a list of lines
The “r” is called the “access mode”. r is for reading, if the file does not exist, an error is raised
w is for writing- If the file exists, the contents are overwritten. If the file does not exist, it will be created
a is for appending- If the file exists new data is appended to the end of the file. If the file does not exist, it will be created
DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!
Watch video Python Tutorial for Beginners 41 Create a Text File and Write in It Using Python online, duration hours minute second in high quality that is uploaded to the channel Expert Programmer 24 November 2019. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 4 times and liked it 0 visitors.