to open file with the open(functionyou pass it string path indicating the file you want to openit can be either an absolute or relative path the open(function returns file object try it by creating text file named hello txt using notepad or textedit type helloworldas the content of this text file and save it in your user home folder then enter the following into the interactive shellhellofile open(path home('hello txt'the open(function can also accept strings if you're using windowsenter the following into the interactive shellhellofile open(' :\\users\\your_home_folder\\hello txt'if you're using macosenter the following into the interactive shell insteadhellofile open('/users/your_home_folder/hello txt'make sure to replace your_home_folder with your computer username for examplemy username is also ' enter ' :\\users\\al\\hello txton windows note that the open(function only accepts path objects as of python in previous versionsyou always need to pass string to open(both these commands will open the file in "reading plaintextmodeor read mode for short when file is opened in read modepython lets you only read data from the fileyou can' write or modify it in any way read mode is the default mode for files you open in python but if you don' want to rely on python' defaultsyou can explicitly specify the mode by passing the string value 'ras second argument to open(so open('/users/al/hello txt'' 'and open('/users/al/hello txt'do the same thing the call to open(returns file object file object represents file on your computerit is simply another type of value in pythonmuch like the lists and dictionaries you're already familiar with in the previous exampleyou stored the file object in the variable hellofile nowwhenever you want to read from or write to the fileyou can do so by calling methods on the file object in hellofile reading the contents of files now that you have file objectyou can start reading from it if you want to read the entire contents of file as string valueuse the file object' read(method let' continue with the hello txt file object you stored in hellofile enter the following into the interactive shellhellocontent hellofile read(hellocontent 'helloworld!reading and writing files