Python vars() Function

Python’s built-in vars() function returns the __dict__ attribute of an object—a dictionary containing the object’s changeable attributes. Without argument, it returns the local symbol table similar to locals(). Python’s built-in vars() function returns a dictionary of name: value mappings of all the names defined in the local scope or the scope of the optional object … Read more

Top 10 Go Cheat Sheets

Hey Finxters! It is time to do yet another cheat sheet! This time we are going to step away from Python (only for a moment!) and discuss GoLang. Unlike Python, which is dynamic- GoLang is a procedural and statically typed language similar to the C programming language. It is currently one of the trending programming … Read more

How to Calculate the Weighted Average of a Numpy Array in Python?

Numpy Weighted Average np.average(array, axis=0, weights=[0.1,0.1,0.8])

Problem Formulation: How to calculate the weighted average of the elements in a NumPy array? Definition weighted average: Each array element has an associated weight. The weighted average is the sum of all array elements, properly weighted, divided by the sum of all weights. Here’s the problem exemplified: Quick solution: Before we discuss the solution … Read more

Python repr() Function — A Helpful Guide with Example

Python’s built-in repr(obj) function returns the standard string representation of the provided object. This often includes the type and memory address of the object—for lack of further information. For example, the returned string representation may be ‘<main.Car object at 0x000001F66D11DBE0>’ for a custom object of type Car. The function internally calls the method obj.__repr__() which … Read more

Python str() Function

Python’s built-in str(x) function converts the object x to a string using the x.__str__() method or, if non-existent, the repr(x) built-in function to obtain the string conversion. Syntax str() Syntax: str(object) # –> Most common case: convert an object to a string str(object=b”, encoding=’utf-8′, errors=’strict’) # –> Not so common case: Converts a bytes or … Read more