Majorly used Data Structures in python are as follows: List Set Tuple Dictionary String Numbers(int, float, decimal) One of the major things in python discussed is whether the data structure is mutable or immutable. What do this terms mean? In simple terms, Immutable means value cannot be changed after it is assigned to a variable. Whereas, In mutable data type value can be changed after assignment. Hmm, What ??? This is still not clear these are merely dictionary definitions I am blabbering. Amazon.in Widgets
In this post, we will look at decorators. We will try to address following questions: What are they? Why they are needed? and when are they useful? Ok, let's look at them one by one. First: What are they? Simply put, From what I understand: Decorators are functions that take another function as input and modifies/extends its functionality. Wait...what? A function that takes another as input? Yes, In Python everything is an object (Classes too.). So we can pass a function as arguments. What do you call a function which takes another function as arguments? : Higher order function. Till now all text, no code. Let's look at an example. Let's write a simple decorator: # Create a simple function. def hello(): print("Hello user!.") # Now we Define a decorator. def my_decorator(some_function): def wrapper(): print("I will check if the user is logged in or not before saying hello!") some_function() ...
Comments
Post a Comment