04-Python Advance

Value equality vs identity

Value equality vs identity

  • Value –> equivalent contents
  • Identity –> same object

Binding Names to Objects

p = [1,2,3]
q = [1,2,3] 
p == q  # --> True    --> val is same
p is q  # --> False   --> not same obj

a = "first"
b = "first"
a is b # --> True
  • NOTE:
    • Immutable object (str, int tuple) refers to same obj if values are same
    • Mutable obj always create new object

Pass by object reference

  • Python uses neither Pass by Value nor Pass by Reference
  • But it uses Pass by Object Reference
[Read More]

07-Python Advance

Multi-threading in Python

7. Multi-threading

Multithreading allows you to break down an application into multiple sub-tasks and run these tasks simultaneously.

If you use multithreading properly, your application speed, performance, and rendering can all be improved.

Multithreading is defined as the ability of a processor to execute multiple threads concurrently.

[Read More]

08-Python Advance

Multi Processing

Multi Processing

Multiprocessing refers to the ability of a system to support more than one processor at the same time.

Applications in a multiprocessing system are broken to smaller routines that run independently. The operating system allocates these threads to the processors improving performance of the system.

[Read More]

OOPs | 01-OOPS concept

class, object, properties and behaviours

1. OOPs, Concept

  • Object Oriented Programming
  • OOP is a specific way of designing a program by using classes and objects
  • It allows us to relate program with real-world objects, like properties and behaviors
  • Properties
    • It defines the state of the object.
    • Like: name, age, address etc. that store data of the object
  • Behaviors
    • Are the actions our object can take.
    • Like: talking, breathing, running etc
    • Oftentimes, this involves using or modifying the properties of our object.
[Read More]

OOPs | 02-Variables

Class and Instance variables

2. Variables/Attribute

In a class all the variables are term as Attribute

There are 3 types of variables are allowed.

  1. Instance/Regular Variables - - Object Level Variables
  2. Class/Static Variables - - Class Level Variables
  3. Local variables - - Method Level Variables
  • Attributes are looked first in the instance and then in the class
[Read More]

OOPs | 03-Methods

Regular, Class and Static methods

3. Methods in python

  • Function
    • Function is block of code that is also called by its name(independent)
    • Function does not deal with Class and its instance concept.
  • Methods
    • Method is called by its name, but it is associated to an object (dependent)

The following are various types of allowed methods:

  1. Instance Methods - - self
  2. Class Methods - - cls
  3. Static Methods
[Read More]

Python intermediate | 03-Type Checking

Type Checking/Annotations in Python

Type Checking/Annotations in Python

  • Type Annotations are a new feature added in PEP 484 that allow for adding type hints to variables.
  • They are used to inform someone reading the code what the type of a variable should be.
  • This brings a sense of statically typed control to the dynamically typed Python
  • Usage
    • Annotate Argument
    • Annotate Return type
    • Annotate Variable
[Read More]