Use Spread Operator to Join Arrays in JavaScript

Nikhilesh Aleti
Updated on 16-Sep-2022 14:39:58

8K+ Views

Array is a variable. Which has an ability to store multiple values in it using appropriate syntax. Every value is referred with index numbers which will start from 0. Const ipl = [“Chennai”, “Mumbai”, Hyderabad”]; Spread operator (…) Spread operator can do the copying of one object or array’s properties and values to another object or array. This will be a shallow copy of the original. Const ipl = [“Chennai”, “Mumbai”, Hyderabad”]; Spread operator can do the copying of one object or array’s properties and values to another object or array. This will be a shallow copy of ... Read More

Find Maximum Value in an Array Using Spread Operator in JavaScript

Nikhilesh Aleti
Updated on 16-Sep-2022 13:22:49

1K+ Views

In this article, we are going to discuss how to find the maximum value in an array using the spread operator in JavaScript. For this you need to understand what is an array, what is spread operator and Math.max() method. Array An Array is a variable which is used to store different types of elements. Used to store a bunch of elements and access them with a single variable. Declaration of array can be done in below methods. var House = [ ]; // method 1 var House = new Array(); // method 2 Spread operator (…) This ... Read More

Clone Array Using Spread Operator in JavaScript

Nikhilesh Aleti
Updated on 16-Sep-2022 13:15:10

3K+ Views

In this article, we are going to discuss how to use the spread operator to clone an array in JavaScript. Cloning is just the process of copying one array into another array. Previously, the slice() method was used to clone an array, however, ES6 now provides the spread operator(...) to simply clone an array. Before proceeding further let us look at the definitions of array and spread operator. Array An Array is usually a data structure, in JavaScript it is an object which can hold multiple values at once. For example, Below “Arr” is an array. Const Arr = [‘Tutorials’, ... Read More

Modify a String In-Place in Python

AmitDiwan
Updated on 16-Sep-2022 13:00:42

2K+ Views

Unfortunately, you cannot modify a string in place because strings are immutable. Simply create a new string from the several parts you want to gather it from. Though, if you still need an object with the ability to modify in-place unicode data, you should for The io.StringIO object The Array module Let’s see what we discussed above − Return a string with the entire contents of the buffer Example In this example, we will return a string with the entire contents of the buffer. We have a text stream StringIO − import io myStr = "Hello, How ... Read More

Floating Point Calculations Inaccuracy in Python

AmitDiwan
Updated on 16-Sep-2022 12:55:08

2K+ Views

What is a float? The floating-point are also called floats, they represent real numbers and are written with a decimal point dividing the integer and fractional parts. Floats may also be in scientific notation, with E or e indicating the power of 10 (2.5e2 = 2.5 x 102 = 250). Why floating-point calculations inaccurate? The floating-point calculations are inaccurate because mainly the rationals are approximating that cannot be represented finitely in base 2 and in general they are approximating numbers which may not be representable in finitely many digits in any base. Example Let’s say we have a fraction − ... Read More

Discover Name of an Object in Python

AmitDiwan
Updated on 16-Sep-2022 12:54:22

1K+ Views

No, there’s no way to discover the name of an object in Python. The reason is that the objects don’t really have names. Let’s say we have the following code. Herein, we cannot find the actual instance name. Since both ob1 and ob2 are bound to the same value, we cannot come to a conclusion that whether the instance name of ob1 or ob2 − Example # Creating a Demo Class class Demo: pass Example = Demo ob1 = Example() ob2 = ob1 print(ob2) print(ob1) Output As we saw above, we ... Read More

Get a List of All Instances of a Given Class in Python

AmitDiwan
Updated on 16-Sep-2022 12:53:20

6K+ Views

The gc or weakref module is used to get a list of all instances of a given class. First, we will install the gc module using pip − pip install gc To use the gc module, use the import − import gc Get the instances of a class using the gc module In this example, we have created a Demo class with four instances − ob1 = Demo() ob2 = Demo() ob3 = Demo() ob4 = Demo() We loop through the objects in memory − for ob in gc.get_objects(): Example Using the isinstance(), each object is ... Read More

Use Strings to Call Functions and Methods in Python

AmitDiwan
Updated on 16-Sep-2022 12:50:43

7K+ Views

Python Functions are generally called using their name. However, you can also use strings to call functions. For that, use the locals() and globals(). Call functions using strings Example In this example, we will learn how to call two functions using strings − def demo1(): print('Demo Function 1') def demo2(): print('Demo Function 2') locals()['demo1']() globals()['demo2']() Output Demo Function 1 Demo Function 2 Call a function using string variable Example In this example, we have created a class Example with the function xyzuvw() that accepts arg and print them. The globals() ... Read More

Specify Hexadecimal and Octal Integers in Python

AmitDiwan
Updated on 16-Sep-2022 12:49:28

10K+ Views

The Hexadecimal and Octal are part of Numeric Types in Python. Let’s see how to specify them one by one. For hexadecimal type, add a preceding 0x. For example − 0x11 For Octal type (base 8), add a preceding 0 (zero). For example − 0O20 Hexadecimal Integers in Python Hexadecimal Number System uses 10 digits and 6 letters, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Letters represent the numbers starting from 10. A = 10. B = 11, C = 12, D = 13, E = 14, F = ... Read More

Make a Higher Order Function in Python

AmitDiwan
Updated on 16-Sep-2022 12:48:24

2K+ Views

A function in Python with another function as an argument or returns a function as an output is called the High order function. Let’s see the propertie − The function can be stored in a variable. The function can be passed as a parameter to another function. The high order functions can be stored in the form of lists, hash tables, etc. Function can be returned from a function. Let’s see some examples − Functions as objects Example The functions are considered as object in this example. Here, the function demo() is assigned to a variable − # ... Read More

Advertisements