coderz.py

Keep Coding Keep Cheering!

@property Decorator in Python

The @property decorator in Python is used to define a method as a “getter” for the boundaries of a class attribute. It allows you to define a method that is accessed like an attribute, without needing to invoke it like a method. Here’s an example: In this example, the @property decorator is used to define […]

January 17, 2023 | python | No comments

Python Decorators

In Python, a decorator is a special kind of function that modifies the behavior of another function. Decorators are often implemented as closures, which are nested functions that can remember and access variables from their containing function, even after the containing function has finished executing. But before diving deep into decorators let us understand some […]

January 17, 2023 | python | No comments

Python Closures

Before we can understand what a closure is, we must first understand nested functions and non-local variables. Nested functions in Python: In Python, a function can be defined inside another function, creating a nested function. A nested function has access to the variables and parameters of the containing function, known as the enclosing function. This […]

January 17, 2023 | python | No comments

Generators in Python

Generator Function: In Python, a generator is a function that allows you to create an iterator, an object that generates a sequence of values. A generator function is defined using the keyword yield, rather than return. When a generator function is called, it returns a generator object, which can be used to iterate over the […]

January 17, 2023 | python | No comments

yield Keyword in Python

The yield keyword in Python is used in the body of a function like a return statement, but when a function with a yield statement is called, it returns a generator object instead of a single value. The generator can then be iterated over to retrieve the values produced by the yield statement one at […]

January 13, 2023 | python | No comments

Iterable and Iterator in Python

What is an Iterable? In Python, an iterable is an object that can be looped over, such as a list, tuple, or string. An iterator is an object that represents a stream of data, and it can be used to traverse through all the elements of an iterable. The built-in function iter() can be used […]

January 12, 2023 | python | No comments

Python __name__ Variable

Because Python lacks a main() function, when the command to run a Python program is given to the interpreter, the code at level 0 indentation is executed. However, it will first define a few special variables. One such special variable is __name__. If the source file is run as the main program, the interpreter assigns […]

January 11, 2023 | python | No comments

Barrier Object in Python

Barrier object in Python is used to synchronize the execution of multiple threads. When a thread reaches a barrier point, it calls the wait() function, and the barrier keeps track of the number of threads that have reached the barrier. When the number of threads that have reached the barrier is equal to the number […]

January 11, 2023 | python | No comments

Condition object in Python

A Condition object in Python is a synchronization object that allows multiple threads to wait for a specific condition to be met. It is similar to a Lock, but it will enable you to synchronize threads not only on the acquisition of the lock, but also on the release of the lock. To better understand […]

January 9, 2023 | python | No comments

Timer Objects in Python

Timer objects are used to schedule a function to be executed at a certain time in the future. The timer is started with a specified number of seconds to wait before executing the function, but the actual time when the function is executed will depend on the availability of system resources and the scheduling of […]

January 7, 2023 | python | No comments

Advertisement