How to Create a file in Python | Python File Handling
How to Create a file in Python | Python File Handling A file is some information or data which stays in the computer storage devices. Python gives you easy ways to manipulate these files. Generally, we divide files into two categories, text file, and binary file. Text files are simple text whereas binary files contain binary data which is only readable by a computer. How to Create a File fobj = open("new.txt","x") for i in range(0,10): fobj.write(f" line no is {i} \n") fobj.close() Various modes of opening a file “r” Opens the file in read-only mode and this is the default mode. “w” Opens the file for writing. If a file already exists, then it’ll get overwritten. If the file does not exist, then it creates a new file. “a” Opens the file for appending data at the end of the file automatically. If the file does not exist it creates a new file. “r+” Opens the file for both reading and writing. “w+” Opens the file for reading and writing. If the file does not exist it creates a new file. If a file already exists then it will get overwritten. “a+” Opens the file for reading and appending. If a file already exists, the data is appended. If the file does not exist it creates a new file. “x” Creates a new file. If the file already exists, the operation fails. “rb” Opens the binary file in read-only mode. “wb” Opens the file for writing the data in binary format. “rb+” Opens the file for both reading and writing in binary format. ============================================================================= Link for Tutorial Series Jupyter Notebook Tutorial Series:- https://www.youtube.com/watch?v=kguFtorzvxk&list=PLWkNktG0P7z8xPPlc1zv7_DobZzFIsWKi Python Tutorial Series:- https://www.youtube.com/watch?v=FL9vhKVhzT4&list=PLWkNktG0P7z-0g6vY1XqeEq2_JuQYRv1P Python Assignments and Objective Questions:- https://www.youtube.com/watch?v=qqhxJmzlDBQ&list=PLWkNktG0P7z9sRRitFMAdkKMutekF7k1M Tech. Videos By Parag Dhawan;- https://www.youtube.com/watch?v=osLpuHDAvn8&list=PLWkNktG0P7z-xGz3B5fG5P9t_4GC133ax Object-Oriented Programming in Python- https://www.youtube.com/watch?v=z_8jY2CoIJY&list=PLWkNktG0P7z8NLuyLIeWUn7B1IEcNNq_T ============================================================================= Feel free to connect and ask your queries:- Linkedin:- https://www.linkedin.com/in/parag-dhawan Youtube:- https://www.youtube.com/c/ParagDhawan Facebook Page:- http://fb.me/dhawanparag Instagram: - https://www.instagram.com/paragdhawan/ Twitter:- https://twitter.com/dhawan_parag GitHub:- https://github.com/paragdhawan/ Facebook Profile:- https://www.facebook.com/profile.php?id=1028424471 ============================================================================= Show your support by Subscribing to the channel:- https://www.youtube.com/c/ParagDhawan?sub_confirmation=1 ============================================================================= #ParagDhawan #PythonCrashCourse #Python #PythonTutorialForBeginners #PythonForDataScience #PythonProgramming #PythonProgrammingLanguage #PythonTutorial #PythonCode #Python3 ============================================================ How to Record Your Screen and make a tutorial video or demo video: - https://www.youtube.com/watch?v=3zmtwAr96_k ============================================================
Download
0 formatsNo download links available.