In JavaScript null is a predefined keyword that represents an empty value or unknown value of no value. The data type of null is an object. In this article, we will learn how to convert null into String using multiple approaches which are following. Using the String() Method Concatenating null with an Empty string Using the Logical OR (||) Using Ternary Operator Using the String() Method The String() in JavaScript is used to convert a value to a String. To convert the null into a String just pass the null into this method. Here is the example ... Read More
In this example, we will see how to find the N largest elements from a List. The list is the most versatile datatype available in Python, which can be written as a list of comma-separated values (items) between square brackets. Important thing about a list is that the items in a list need not be of the same type Let’s say the following is the input list − [25, 18, 29, 87, 45, 67, 98, 5, 59] The following is the output displaying the N largest element from the list. Here, N = 3 − [98, 87, 67] ... Read More
In JavaScript null is a predefined keyword that represents an empty value or unknown value of no value. The data type of null is an object. In this article, we will learn how to convert null into Boolean using multiple approaches which are following. Using Number() Method Using Logical OR (||) Using the ~~ operator Using Ternary Operator Concatenating null with a boolean value Using the Number() Method The Number() method in JavaScript is used to convert a value into a number. If the value is not convertible, then it will return NaN. To convert the null into ... Read More
In JavaScript null is a predefined keyword that represents an empty value or unknown value of no value. The data type of null is an object. In this article, we will learn how to convert null into Boolean using multiple approaches which are following. Using the Boolean function Using the !! operator Using the Boolean function The Boolean function is used to get the Boolean value (true or false) of any variable, condition, or object. To convert the null into Boolean we just need to pass the null in the Boolean function. Syntax Boolean(null) Example 1 In this example, ... Read More
In this tutorial, we will learn how to convert NaN to String. NaN in JavaScript means Not a Number, whose type is Number but actually, it is not a number. To Convert, the NaN to a String we use Multiple methods some of which are discussed below. Using the String() Method Using the toString Method Using the || Operator Using the isNaN() Method Using Ternary Operator Using the String() Method The String() method in JavaScript is used to convert different values to String. To convert the NaN into String Just pass the NaN to this method. Here is ... Read More
In this article, we will see how we can create an empty functions in Python. A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ). Here, we will see examples of Empty Functions. Empty Function Use the pass statement to write an empty function in Python −Example # Empty function in Python def demo(): pass Above, ... Read More
In this article, we will find the first non-repeating character from a stream of character. Let’s say the following is our input − Thisisit The following should be our output displaying first non-repeating character − H Find the first non-repeating character from a stream of characters using while loop We will find the first non-repeating character, by comparing each character with the other using a loop − Example # String myStr = "thisisit" # Looping while myStr != "": slen0 = len(myStr) ch = myStr[0] myStr = myStr.replace(ch, "") slen1 = len(myStr) if slen1 == slen0-1: print ... Read More
We will learn how to swap two variables in one line. Let’s say the following is our input − a = 10 b = 5 The following is our output after swap − a = 5 b = 10 Swap two variables in one line using comma operator Using the comma operator, you can create multiple variables in a single line. The same concept is considered here and the variable values are swapped − Example a = 5; b = 10; print("Variable1 = ", a); print("Variable2 = ", b); # Swap two variables in one line ... Read More
JavaScript is an untyped language because in JavaScript the variables can hold any data type meaning that JavaScript does not have a type declaration and when the variable is created we do not need to specify any data type unlike other programming languages like Java, C#, C++, etc. which needs int, char, float, etc. to create a variable. In JavaScript we use var, let, and const to create a variable. One of the best parts of untyped language is it gives the flexibility to reassign any type of value to a variable, it doesn't matter whether the initialized value was ... Read More
To check if a string is a valid keyword, import the keyword module and use the iskeyword() method. With that, you can directly display all the keywords at once and verify. Let’s say the following is our input − else The following is the output. The “else” is a keyword in Python − Keyword Check if a string is a valid keyword in Python Example import keyword # Create a List myList = ["for", "amit", "val", "while"] # Display the List print("List = ", myList) keyword_list = [] non_keyword_list = [] # Looping and ... Read More