Python file handling

By // No comments:

  • Files are basically used to store and write the data.
  • Files are used to permanently store the data in a non volatile memory(pen drive ,hardisk).
  • We were taking the input from the console and writhing it back to the console.It is not enough,if we want to display more data then it is not display on the console because data are temporely stored in RAM (volatile memory).when we off or shut down the computer/pc ,data will be lost.So that here file input/output concepts are more important.
  • The file handling plays an important role when the data needs to be stored permanently into the file.
  • When we use files,we can access the stored information after the program termination because files are non volatile storage.
  • When we want to read ,write and modify the file ,we  need to open it first.
  • After performing the read ,write and modification in the file,we have to close the file.
Hence a file operation can be done in the following order.
  1. Open a file.
  2. Read or write(operations)
  3. Close the file.
3

Exception Handling in python with examples

By // No comments:

 Python Exception:-

  • An exception is an unusal things in a program that cause the interruption in flow of program.
  • An exception is the run-time errors that are unable to handle the python program.
  • While creating and executing a python script things may go worng at two different stages:-
  1. During compilation
  2. During execution

  • Error that occurs during compilation time,are called syntax error.The Error that occurs during execution or run time, are called exceptions or run-time error.
  • Python provides a way to handle the exception so that the program/codes can be executed without any interruption.
  • Python has many built-in exceptions that enable program to run without interruption and give the output of the code.
3

Encapsulation In Python with examples

By // No comments:

 Encapsulation:-

  • Encapsulation is a important concept of object oriented programming language.
  • In encapsulation methodology we can restrict access to methods and variables.
  • To prevent the data access of the class from out side or same class, is known as encapsulation.
  • In python ,we denote private attributes using prefix underscore(single(_) or double(__)).
  • It is used to hide the entire class data from the outside source. 
Benefits and needs of Encapsulation in python:-
  • Encapsulation concepts not only ensure better data flow but also protects the data from the outside sources.
  • Encapsulation is helpful to achieving well -defined interaction in each applications.
  • Encapsulation helps to secure the python applications.
  • Encapsulation ensures the data security and avoids the access the data accidentally.
Python allows us to access the method and variables from the outside the class as given below:-
3

Polymorphism concepts in python with example

By // No comments:

  • Polymorphism word is made Greek words poly(many) and morphism(shape/forms).
  • It means we can use same method/function name  for different types.
  • We generally uses two types of polymorphism in c++,java ,c# etc.But python support only one polymorphism that is called run-time polymorphism.
Types of Polymorphism :-
  1. Compile time polymorphism (e.g. method overloading)
  2. Run-time polymorphism (e.g. method overriding)
  1.) Compile time polymorphism:- 
  • It is used for method overloading.
  • It support compile-time binding.Python  does not support compile time polymorphism.
  • In this, class ,method and object are bind at compile time.
3

Inheritance Concepts in python with example

By // 1 comment:

There are some important points to define inheritance concepts in python.

  • Inheritance is the most important concept of object-oriented programming  language.It simulates the real world concepts of inheritance.
  • In inheritance, a new class called derived class can be created to inherit features of an existing class called base class.
  • Base class is also known as super class or parent class.
  • Derived class is also know as sub class or child class.
  • In inheritance,when we create the object of child class.Then this child class object acquires all the properties and behaviors of the parent object. 
  • Inheritance concept provide the re-usability of code.
3

oops concepts in python with real life example

By // 1 comment:

  •  OOP(object oriented programming) is used to solve the problems with the help of  classes and objects.
  • Python is an object oriented programming language like c++,java and c#.
  • We can easily develop the applications using this object oriented approach.
  • An object oriented paradigm is used to design the program using using classes and objects.
  • This oops concepts in python focuses on creating reusable code.
There are some major concepts is used in oops(object -oriented programming system) as given below.
  1. class 
  2. object
  3. method
  4. Inheritance
  5. Polymorphism
  6. Encapsulation
  7. Abstraction
1.) Class:
  • A class is a blue print of an object.
  • A class is a collection of data and methods
3

Constructor concepts in python

By // No comments:

 A Constructor is a special type of method which is used to initialize the object of the class.In c++ and java ,the constructor is the same name as its class.But in python,it is different .Hence we use __init__() as a special method to simulates the constructor of the class.This special method is called when the object of the class is created.

  • The __init__() method accepts the self keyword as a first argument which is used to access the methods or attributes of the class.
  • We can pass the any number of arguments at the time of object creation according to definition of __init__() method.
  • The constructors are mainly used to initialize the class attributes.
  • In python,every class must have a constructor even it may be a default constructor.
3
Powered by Blogger.