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 with examples

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

Classes and Objects Concepts in Python

By // No comments:
Python classes and objects

Python is an object oriented programming language .Every things in python treated as an object.python supports structured as well as object oriented programming language paradigms.

  • A class contains data and  methods that can access or manipulate this data.Thus a class is a collection of data and methods.A class is a blueprint (prototype) of an object. Thus a class lets us bundle data and functionality together.
  • A user-defined blueprint/prototype for an object is known as class.example : House is an object where blueprint/prototype/model of house is known as a Class.
  • A class is generic in nature,whereas an object is specific in nature.
  • We can create many objects from one class.We can easily access the class member with the help of these objects.
  • An object is also an instance of a class The process of creating this object  is called instantiation
  • We can  also create our own classes.These are often called user defined data types but we generally uses ready-made classes in python.
3
Powered by Blogger.