Display the Contents of a Text File in Reverse Order in Python

AmitDiwan
Updated on 15-Sep-2022 12:27:46

5K+ Views

We will display the contents of a text file in reverse order. For that, let us first create a text file amit.txt with the following content  Display the contents of a text file in Reverse Order with Slicing Example Let us now read the contents of the above file in reverse order − # The file to be read with open("amit.txt", "r") as myfile: my_data = myfile.read() # Reversing the data by passing -1 for [start: end: step] rev_data = my_data[::-1] # Displaying the reversed data print("Reversed data = ", rev_data) Output Reversed ... Read More

Load JavaScript Function Using Variable Name

Shubham Vora
Updated on 15-Sep-2022 12:26:54

1K+ Views

In this tutorial, we will learn to load a JavaScript function using the name of a variable. Functions are the block of statements that takes an input and displays the result to the user after an execution. We can use these blocks of codes repeatedly by only declaring the function, and these functions can help a programmer in many ways as it also reduces efforts. JavaScript also supports the use of functions like other programming languages. Functions in JavaScript can be either built-in or user-defined. There are different ways to declare a function and call it. Generally, a simple Function ... Read More

Difference Between del and remove on Lists in Python

AmitDiwan
Updated on 15-Sep-2022 12:26:34

9K+ Views

Let us understand what is Del and Remove() in a Python List before moving towards the difference. Del Keyword in Python List The del keyword in Python is used to remove an element or multiple elements from a List. We can also remove all the elements i.e. delete the entire list. Example Delete an element from a Python List using the del keyword #Create a List myList = ["Toyota", "Benz", "Audi", "Bentley"] print("List = ", myList) # Delete a single element del myList[2] print("Updated List = ", myList) Output List = ['Toyota', 'Benz', 'Audi', 'Bentley'] Updated ... Read More

Get Smallest Integer Greater Than or Equal to a Number in JavaScript

Shubham Vora
Updated on 15-Sep-2022 12:24:52

3K+ Views

In this tutorial, we will learn how to get the smallest integer greater than or equal to a number in JavaScript. To get the smallest integer greater than or equal to a number, use the JavaScript Math.ceil() method. This method returns the smallest integer greater than or equal to a given number. In other words, the Math.ceil() method rounds a number and returns an integer result. Because the ceil() method is a static function of the Math object, it must be invoked via the Math placeholder object. The ceil() method produces the lowest integer value that is bigger than or ... Read More

Replace All Occurrences of a Python Substring with a New String

AmitDiwan
Updated on 15-Sep-2022 12:24:19

288 Views

In this article, we will implement various example to replace all occurrences of a substring with a new string. Let’s say we have the following string − Hi, How are you? How have you been? We have to replace all occurrences of substring “How “ with “Demo”. Therefore, the output should be − Hi, Demo are you? Demo have you been? Let us now see some examples − Replace All Occurrences of a Python Substring with a New String using replace() Example In this example, we will use the replace() method to replace all occurrences of a Python Substring with ... Read More

Get Largest Integer Less Than or Equal to a Number in JavaScript

Shubham Vora
Updated on 15-Sep-2022 12:23:02

820 Views

In this tutorial, we will learn how to get the largest integer that can be less than or equal to a number in JavaScript. To get the largest integer less than or equal to a number, we use the Math.floor() method in JavaScript. It is used to round off a number supplied as a parameter to its closest integer towards the downward direction of rounding, i.e., towards the less significant value. Following are two ways in which we find the largest integer that can be less than or equal to a number in JavaScript. Using Math.floor() Method The method Math.floor() ... Read More

Get ID of a Form with Dropdown List using JavaScript

Shubham Vora
Updated on 15-Sep-2022 12:20:37

5K+ Views

In this tutorial, we will learn how to get the id of a form containing a dropdown list using JavaScript. The id property of an HTML element gives a unique id. The id property value must be unique inside the HTML content. The style sheet property points to a specific declaration of style. JavaScript also uses it to access and alter the element with the specified id. The id property is used to provide an element with a unique identifier. On a web page, you cannot have more than one element with the same id. A dropdown menu in a ... Read More

Merge Elements in a Python Sequence

AmitDiwan
Updated on 15-Sep-2022 12:19:18

2K+ Views

Python Sequences includes Strings, Lists, Tuples, etc. We can merge elements of a Python sequence using different ways. Merge Elements in a Python List Example The join() method is used to merge elements − # List myList = ['H', 'O', 'W', 'A', 'R', 'E', 'Y', 'O', 'U'] # Display the List print ("List = " + str(myList)) # Merge items using join() myList[0 : 3] = [''.join(myList[0 : 3])] # Displaying the Result print ("Result = " + str(myList)) Output List = ['H', 'O', 'W', 'A', 'R', 'E', 'Y', 'O', 'U'] Result = ['HOW', 'A', 'R', ... Read More

Case Insensitive Matching with JavaScript RegExp

Shubham Vora
Updated on 15-Sep-2022 12:18:08

4K+ Views

In this tutorial, we will learn how to perform Case Insensitive matching with JavaScript RegExp. Regular expressions can be declared in two ways − Using regular expressions literal, which start and end with slashes, and the pattern is placed in between. Calling the RegExp object constructor, which takes the pattern and flags in the parameters to create a regular expression. Users can use the below syntax to create a regular expression. Syntax //Using a regular expression literal const regex = /tutorial/i //Using RegExp constructor const regex2 = new RegExp('tutorial', 'i') In the above syntax, the regular expressions ... Read More

Check If All Characters in a String Are Alphanumeric in Python

AmitDiwan
Updated on 15-Sep-2022 12:17:18

519 Views

To check if all the characters in a string are alphanumeric, we can use the isalnum() method in Python and Regex also. First, let us understand what is alphanumeric. What is Alphanumeric? Alphanumeric includes both letters and numbers i.e., alphabet letter (a-z) and numbers (0-9). Examples: A, a, k, K, 8, 10, 20, etc. Let us see an example of an Alphanumeric string 8k9q2i3u4t Let us see an example of a string wherein all the characters aren’t Alphanumeric - $$###k9q2i3u4t Check If All the Characters in a String Are Alphanumeric using isalnum() We will use the built-in isalnum() ... Read More

Advertisements