1. Using file handling we can do file operations # How to open a file in python ? 1. We can open a file two ways in python 1. open() 2. With open() # OPEN 1. Using open we can open only one file at a time and we have to close a file explicity # WITH OPEN 1. Using with open we can open multiple files at a time and no need to close files explicity # File Open Modes In Python r ==> It opens a file for read only. w ==> It allows write-level access to a file. If the file already exists, then it’ll get overwritten. It’ll create a new file if the same doesn’t exist. a ==> It opens the file in append mode. a+ ==> It opens a file FOR append AND read rb ==> It opens a binary file for read 1) Read file fh = open('names.txt', 'r') ## To open a file from another path #fw = open(...
Python Programming tutorial provides basic and advanced concepts of Python programming. This Python programming tutorial is designed for beginners and professionals. Python is a simple, general purpose, high level, and object-oriented programming language. In this we have different chapter and their concepts Python Programming : tokens, literals, identifiers, keywords, special symbols and operators; fundamental data types, expressions, type conversions, handling Input and output in Python. Selection Statements : if statement, if-else statement, if-elif-else statement, nested-if statement. Iterative Statements : while loop, for loop, break statement, continue statement, pass and else statements used with loops. Sequences : Lists and operations - creating, inserting elements, updating elements, deleting elements, searching and sorting, list comprehensions, nested lists; tuples - creating, searching and sorting, nested tuples; strings - Initializing a...
''' 1. Encapsulation is the process of wrapping up variables and methods into a single entity. In programming, a class is an example that wraps all the variables and methods defined inside it. class One(): name = 'umamahesh' def add(self): print(' ADD is ') def sub(self): print(' SUB is:') ins = One() print('\n ', ins.name) --Using encapsulation we can give protection to the class members. It can achieve Using access modifiers. Encapsulation can be achieved using Private and Protected Access Members. ''' Example---CSE department faculty cannot access the ECE department student record and so on. Here, the department acts as the class and student records act like variables and methods. =======Why Do We Need Encapsulation?=========== ===Encapsulation acts as a protective layer by ensuring that, access to wrapped data is not possible by any code define...
Comments
Post a Comment