In Python, the backslash-escaped string contains the characters that are followed by backslash(\), which are used as escape characters. For example, represents the literal characters "" and "n" (not a new line). In some scenarios, we need to unescape such a string, i.e, convert these sequences back to their intended special characters or read them as normal text. Python provides several ways to achieve this. In this article, we will explore how to un-escape a backslash-escaped string. Using Python .decode() Method The Python decode() method is used to decode the string using the codec ... Read More
Wrapping the string means formatting or breaking the string so that it fits within the specified width. It is useful when writing the content to the file, such as logs or console-like outputs. Python provides various ways to achieve string wrapping before writing it to the file using the built-in methods. In this article, we are going to learn how to wrap a string in a file in Python. Using Python textwrap.wrap() Method The textwrap.wrap() method is used to wrap a single paragraph of text. so that every line is at most a specified length. It accepts a text ... Read More
In this article, we are going to learn how to convert a string to JSON in Python. JSON is a lightweight data interchange format that is used to read and write, and store data. Usually, we receive JSON data in the form of a string. To process it using a Python program, we need to convert the JSON string into an object, which can be stored in Python dictionaries and lists. This conversion can be done by using functions provided by the Python JSON module. Using Python json.loads() Function The Python json.loads() function is used to convert the JSON-formatted ... Read More
The pointers can be directly compared using relational operators. In this article, we will learn about the comparisons of the pointers with the help of examples. Pointers Comparison in C and C++ In C/C++, we can directly compare the pointers using relational operators (==, !=, , =). These operators are used to compare two variables, values, or pointers. It returns a Boolean true value when the comparison is correct otherwise, it is false. The core syntaxes of C and C++ pointers are similar such as declaration, dereferencing, and pointer arithmetic. All of these are identical in behavior and still use ... Read More
In C, you cannot use a function call on the left side of an assignment if it returns a value because function calls return non-assignable values. For example, function_name() = value; However, if the function returns a pointer, you can dereference it to assign a value. For example, *function_name() = value; In C++, the same rule applies. You can use the returned reference/pointer on the left side to modify the original variable which is valid only if it returns a reference. function_name() = value; Note: References allow direct access to variables, and pointers allow indirect access via dereferencing. ... Read More
ASCII stands for the American Standard Code for Information Interchange. It represents the characters using the integer value from 0 to 127. In this article, we are going to explore the different ways to check if a string contains only ASCII characters in Python. It is necessary to verify whether a string contains only ASCII characters when ensuring compatibility. Using Python isascii() Method The Python isascii() method is a built-in method in Python 3.7. It returns true if all the characters in the string are ASCII; otherwise false. Syntax Following is the syntax for the Python isascii() method - ... Read More
In C/C++, a null pointer is a special pointer that does not point to any valid memory location. Address 0 is used for Null Pointers because address 0 is reserved by the system, and it is guaranteed not to be used for valid data. So, when a pointer is assigned the value 0 (or nullptr), it means the pointer points to nothing. Some uses of null pointers are: To initialize a pointer variable when that pointer variable isn't assigned any valid memory address yet. To pass a null pointer to a function ... Read More
The binary file stores data in binary format, and data can be written using the write() or fwrite() method in C++. Writing to a Binary File To write a binary file in C++, use write method like fwrite()/write() method. It is used to write a given number of bytes on the given stream, starting at the position of the "put" pointer. The file is extended if the put pointer is current at the end of the file. If this pointer points into the middle of the file, characters in the file are overwritten with the new data. If any error ... Read More
The ArrayList and LinkedList classes implement the List interface of the java.util package. This interface provided two variants of the remove() method to remove particular elements, as shown below - Using remove(int index) Using remove(Object o) There are two additional removal approaches provided by the Collection and Iterator interfaces. They are - ... Read More
Binary search is the fastest algorithm for finding an item from a sorted list of items. C++ STL provides built-in functions to perform binary search operations on sorted ranges of elements. In this article, we will learn binary_search, lower_bound and upper_bound functions in C++ STL. First of all, let's understand what binary search is. What is Binary Search? Binary search is a fast search algorithm with run-time complexity of (log n). This search algorithm works on the principle of divide and conquer, since it divides the array into half before searching. This algorithm works only on sorted collection of ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP