In this article, we’ll take a deep dive into exactly what happens when we instantiate a new object in Python. With this knowledge in hand, we can exercise fine control over instance creation, which can allow us to customize Python objects in powerful ways. So let’s get started.
So what happens behind the scenes when we create a new object in Python?
Let’s try to understand this using a basic class example that models Employee entity.
def __init__(self, name, age):
print(type(self), self.__dict__) # debug stat. self.name = name
print(self.__dict__) # debug stat. self.age = age
Closures are elegant Python constructs. In this article, we’ll learn about them, how to define a closure, why and when to use them.
But before getting into what a closure is, we have to first understand what a nested function is and how scoping rules work for them. So let’s get started.
Whenever a function is executed, a new local namespace is created which represents the local environment that contains names of function parameters and variables assigned inside the function body. …
Python provides us the capability to execute a directory or a zip file directly. Something which is not widely known in the Python community. Therefore, this blog post aims to uncover that. Also, in the process, we’ll acquire few less-known python tricks up our sleeves. So let’s dig in.
It is very straightforward to execute a directory in Python. All we have to do is make sure there is a
__main__.py file present in that directory. Let’s understand it by considering an example. Here we have a file __main__.py with the following contents:
# file __main__.pyname = "Sarah"
Understanding networking in Kubernetes is paramount. Understanding Services can let us enable our pods to talk to each other and choose the right strategy based on the origin of traffic (either from within or outside the cluster) for our user-defined applications and services.
This article aims to cover the significance of Services in a Kubernetes cluster, the various shortcomings they overcome, followed by various types of Services objects offered by k8, their capabilities, and when to use each one of them.
Deep learning in computer vision has made rapid progress over a short period. Some of the applications where deep learning is used in computer vision include face recognition systems, self-driving cars, etc.
This article introduces convolutional neural networks, also known as convnets, a type of deep-learning model universally used in computer vision applications. We’ll be deep-diving into understanding its components, layers like convolutional layer, pooling layers, and fully connected layers and how they can be applied to solve various problems.
So let’s get started.
Above is an image of a cat, as a kid we are told that this animal…
Python has lots of cool features such as first class functions, lambdas, generators, comprehensions etc. There are plenty of articles on the subject. However, there are some of the features in Python, which are generally not so commonly used.
In this article, we’ve tried to summarize some of the these features, which will provide us a better knowledge on the subject and can come in handy at times for developers.
So let’s dive in!
Resources like CPU, memory utilised by our Python program can be controlled using the resource library.
To get the processor time (in seconds) that a process…
Coordinated Universal Time (UTC) is the standard, time-zone independent representation of time. UTC works great for computers that represents time as seconds since the UNIX epoch (starting point against which we can measure the passage of time).
For example, if we define the epoch to be midnight on January 1, 1970 UTC — the epoch as defined on Windows and most UNIX systems — then we can represent midnight on January 2, 1970 UTC as
86400 seconds (
24 * 60 * 60) since the epoch.
But UTC isn’t ideal for humans. Since we usually refer time relative to where we’re…
In this article, we’ll learn about the anonymous function, also known as lambda functions. We’ll try to decode as to why there’s a big fuss about lambdas, understand their syntax and when to use them.
So Let’s jump right in.
The lambda keyword in Python provides a shortcut for declaring small anonymous functions. Lambda functions behave just like regular function declared with def keyword. They can be used whenever function objects are required.
For example, this is how we’d define a simple lambda function carrying out an addition:
>>> add = lambda x, y: x + y
>>> add(22, 10)…
This article details how to create generator functions and why we would want to use them in the first place.
The simplest choice for functions that produce a sequence of result is to return a list of items. For example, let’s say we need to find the index of every word in the string. Here, we accumulate results in a list using the append method and return it at the end of the function.
result = 
for index, letter in enumerate(text):
if letter == ' ':
result.append(index + 1)
This works as…
An array is a fundamental data structure available in most programming languages, and it has a wide range of uses across different algorithms.
In this article, we’ll take a look at less known array implementation in Python that only use core language features that’s included in Python standard library.
We’ll see the strengths & weaknesses of each approach so we can decide which implementation is right for our use-case. But before we jump in, let’s cover some of the basics first.
How do arrays work, and what are they used for?
Arrays consist of fixed-size data records that allow each…
Sports Enthusiast | Senior Deep Learning Engineer. Python Blogger @ medium. Background in Machine Learning & Python. Linux and Vim Fan