Search This Blog

Sunday, 9 June 2999

Headlines

PEARLS OF WISDOM 

Pearls of Wisdom is my youtube channel affiliated to Enlightened Thought Works, whose objective is to provide motivational booster shots, to help uplift individual morale.
These videos are 3min-5min boosters, with introspection points, that can leave you staying motivated throughout the day.
  1. The channel has uploads everyday in the form of 15sec - 45sec motivation #shorts
  2. The channel also uploads long videos which are 3min - 5min, on real success stories, motivational experiments every Monday.
We have come accross a lot of sad and sensational stories in this year of COVID-19. Let's spread joy and boost our morale to get ready for a better future!

Do support us in this initiative by subscribing to this channel, so that we can provide more of such motivational booster shots in the form of youtube videos. 
Click on the url below, to subscribe to our channel Pearls Of Wisdom.


You can also embed the Pearls of Wisdom Audio-visual Quotes widget on your website, which would increase the User Experience and user connect with your website. Just add the widget below, anywhere in your website and see the magic happen.

The widget would look something like this.








          







Thursday, 24 July 2025

Rest APIs using Python

Understanding REST APIs

A REST API is like having a conversation with a web server using the HTTP protocol. You send an HTTP request, and the server replies with an HTTP response.

 


KEY COMPONENTS IN A REST API INTERACTION ARE

A. HTTP Request: In simple words it means: You Ask for Something

Every request includes:

  • Method: What you want to do (GET, POST, PUT, DELETE)
  • URL: The address of the resource (/users, /posts/1)
  • Headers: Extra info like content type (application/json)
  • Body: Data sent (for POST, PUT, etc.)

Example:



B. HTTP Response: Server Replies

A response includes:

  • Status Code: Was it successful? (200 OK, 404 Not Found, 201 Created)
  • Headers: Info about the response
  • Body: The actual data (often JSON)


Key methods used in HTTP Operations


WORKING WITH REST APIs IN PYTHON

What Is urllib?

urllib is part of Python’s standard library and includes submodules like:

  • urllib.request: for opening and reading URLs
  • urllib.parse: for encoding query parameters
  • urllib.error: for handling exceptions

No installation needed — it’s ready to go out of the box! 

We shall use this library to work with Rest APIs

Please refer to the following trinket to see an example on GET, POST, PUT, DELETE operations in Python





Wednesday, 23 July 2025

OOPs in Python

Python supports rich object-oriented programming (OOP) features that promote modularity, scalability, and readability. In this article, we’ll explore core OOP concepts using Python’s syntax and conventions—ideal for building GUI apps, REST APIs, and creative projects.

Classes: They are like a template to create new objects. Similar to the blueprint of a house plan created by the architect.


Constructor: 

Every class has a constructor. This ensures that the object is created and loaded in the application memory with its settings as provided in the constructor. This is similar to the architect of the house instructed the contractor how to lay the foundation with which material and how it needs to be placed etc.

This is done using python's built-in function __init__(self).
This is a special function which will be invoked by python at runtime. You can see the above example with the __init__(self, <parameters>)
where,
self : here indicates the current context of the object created

Inheritance
Inheritance lets one class absorb properties and behaviors of another.


Syntax: 

class Child(Parent):
            ... your code here ...

Let's take the example of senior developer:



** NOTE: Please note, the above class does not have __init__()

Here, we need to understand, that until the parent class is constructed the child class cannot be constructed. Hence order of construction of object in execution, in the case of inheritance is
1.  parent __init__() 
2. child __init__()

CASE: In case the parent constructor has parameters apart from self, then how can these be supplied in inhheritance case?

ANS: Use super().__init__(parent-parameter-values)

Hence the above code will be modified to call the parent class constructor as follows:



Access Specifiers:
The following conventions are used to specify access.


See the following example:
Here instance properties are created where values assigned are native to that specific object only.



Statics:These are shareable variables and function. They are invoked using

ClassName.<static_member>

See the following example:


Overriding: The concept of  changing the behaviour of a function (logic of the function) in the child class is known as overriding




Overloading: The concept of creating a function with the same name but different parameters is known as overloading. Python does not support overloading. This can be done by using *args, **kwargs kind of parametersin the function

Play around with the following trinket showing all the above explained operations as an example



Monday, 21 July 2025

Python Basics: Lambdas

 

Lambdas in Python are like mini-functions without a name, perfect for short, quick operations—think of them as the “Post-it notes” of the coding world: compact, purposeful, and disposable.

What Is a Lambda Function?

A lambda in Python is an anonymous function defined using the lambda keyword. It’s used when you need a simple function for a short period and don’t want to formally define it with def.

Syntax Breakdown

lambda arguments: expression

  • You can pass multiple arguments, but only a single expression.
  • You can’t use statements like loops or conditionals—just expressions.


def traditional_square(num):
    return num * num

square = lambda num: num * num  #defined the function
print(square(5))


Common Use Cases

Use Case

Example

        With map()    

        map(lambda x: x*2, [1, 2, 3])[2, 4, 6]

        With filter()

        filter(lambda x: x > 0, [-1, 0, 1])[1]

        With sorted()

        sorted(words, key=lambda x: len(x)) → sort by length

        Quick function

        lambda x, y: x + y



Python Basics: Dictionaries

 

What Is a Dictionary in Python?

A dictionary is a built-in data type that lets you store data in key-value pairs. Instead of accessing values by a number (like in a list), you access them by their label.

Syntax



When to Use Dictionaries

Use them when:

  • When working with Json data
  • This works well with data returned from Database / backend
  • You want fast lookup by a unique key
  • You're organizing settings, user profiles, configurations, etc

Common methods used with dictionaries




See the following code and try it yourself






Thursday, 17 July 2025

Python Functions using global and comprehension

 In the earlier article, we have seen the use of global, and the different flavors of functions in Python.

Let''s combine them and use comprehensions to reduce the total lines of code.

What are comprehensions in Python?

In Python, comprehensions are a concise and expressive way to create new sequences—like lists, sets, dictionaries, or generators—from existing iterables. They let you write elegant one-liners that would otherwise require multiple lines of loops and conditionals.

Comprehensions work like the Arabic language, read from right-to-left

🔍 Observations

  • In the above screenshot, in modify(old_emp, new_emp), the execution happens in a sequential top-to-down manner.
  • In modify_smart(old,new), the same execution happens in one-line from right to left

Let's highlight the comprehension in the modify_smart()

🔍 Investigating the above code: 

  • for emp in company_employees: Iterate over each employee name in the list.
  • new if emp == old else emp: If the employee name matches old, replace it with new; otherwise, keep it unchanged.

Python Basics: Using Globals

 What is the use of Global keyword

The global keyword is used to declare that a variable inside a function refers to a variable defined in the global scope—outside the function. Without it, Python treats variables assigned inside a function as local by default.

Each function runs in its own scope. Any changes made in it are confined within the scope of the function.

Hence, if a variable name is declared outside the function and is later modified inside the function, the modifications made inside the function will not reflect in the variable declared outside the function.

This functions similar to having a secret-lingo within friends. Outside the friends circle the same secret-lingo will not be shared. Modification to outer variables inside the functions also work in a similar way.

🔍 Understanding the above code

  • secret_lingo is a global string that holds our "secret message".
  • update_lingo() uses global secret_lingo to modify it from inside the function.
  • reveal_lingo() just prints the current value.

Let's try this with collection types. Here, we shall take the example of lists

Unlike for primary datatypes, the collection types will need the global keyword to be used only if there is an assignment operation inside the function.
For modification of collection items, removal of items, appending items to the collection use of globals keyword  is not required

No need to use global keyword in the case shown below


Reassigning the list (needs global)



Updating the list (no need of global)