You must have noticed that till now we have been learning one new concept per tutorial. For some important concepts like loops we had to allocate two tutorials so we can grasp the concept of both loops (for and while) separately. But now in the case of file we have allocated next five tutorials (excluding the exercise and their solutions). So, from this you can take a hint that how important file handling is in programming.
In this tutorial we are not getting into files in detail, instead we are discussing the basics of file and its modes in a theoretical manner. In computer terms, “a file is a resource for saving data and information in computer hardware”. A file is stored in the form of bytes in hardware. A file is opened in the RAM, but it is stored in the Hardware because hardware is non-volatile i.e. it stores its data permanently. On the other hand, RAM is volatile, it loses its data when the system is shut down.
Unlike C or C++, file handling in python is relatively easy and simple. Python treats file differently as text or binary and this is important. There are two types of files that we normally encounter in our computer daily. The first one is text file and the second one is binary file. We can understand by the name of text file that it must contain text in it. The extension for text file is .txt. All other forms of files are mostly binary even a .doc file, that we open in Microsoft Word is a binary file because it requires a special software for accessing it.
The second sort of files are binary files. They are almost all the other files that we come in contact with while using our computer. These files include images, pdf’s, excel files etc.
Modes of opening file in Python:
There are many modes of opening a file in Python, unlike other languages Python has provided its users a variety of options. We will discuss seven of them in this tutorial.
# list1 = [ ["Harry", 1], ["Larry", 2], # ["Carry", 6], ["Marie", 250]] # dict1 = dict(list1) # # for item in dict1: # print(item) # for item, lollypop in dict1.items(): # print(item, "and lolly is ", lollypop) items = [int, float, "HaERRY", 5,3, 3, 22, 21, 64, 23, 233, 23, 6] for item in items: if str(item).isnumeric() and item>=6: print(item)
No downloadable resources for this video. If you think you need anything, please post it in the QnA!
Any Course related announcements will be posted here