Yaswanth Varma has Published 377 Articles

How do I un-escape a backslash-escaped string in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 17-Jun-2025 15:35:02

9K+ Views

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 ... Read More

How do I wrap a string in a file in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 17-Jun-2025 15:26:54

3K+ Views

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 ... Read More

How to Convert String to JSON using Python?

Yaswanth Varma

Yaswanth Varma

Updated on 17-Jun-2025 15:03:01

2K+ Views

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 ... Read More

How to check if a string in Python is in ASCII?

Yaswanth Varma

Yaswanth Varma

Updated on 17-Jun-2025 14:45:10

2K+ Views

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 ... Read More

How to detect vowels vs consonants in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 13-Jun-2025 17:39:56

6K+ Views

In the English alphabet, letters are categorized into vowels and consonants. The vowels are (a, e, i, o, u), and the remaining alphabetic characters are considered as consonants. In this article, we are going to detect the vowels vs the consonants in Python. Python provides a simple way to ... Read More

When to use %r instead of %s in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 13-Jun-2025 16:24:05

4K+ Views

Using %r instead of %s in PythonIn Python, string formatting is done by using the %(formatting operator). The %s uses the str() to convert the value, while the %r uses the repr() to convert values. Both operators look similar, but the difference is that they serve different purposes: ... Read More

How to find longest repetitive sequence in a string in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 10-Jun-2025 19:20:08

3K+ Views

Strings are the essential data types used in many real-world problems that involve analysing and manipulating text data. In this article, we are going to learn about finding the longest repetitive sequence in a string. The Repetitive sequence refers to a substring that appears more than once in the ... Read More

What is an efficient way to repeat a string to a certain length in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 10-Jun-2025 19:19:10

1K+ Views

In Programming, it is useful to repeat or pad a string up to a certain length. Whether generating the formatted output, filling templates, or being able to repeat the string to a specific length can save time. In this article, we are exploring an efficient way to repeat a string ... Read More

Why substring slicing index out of range works in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 10-Jun-2025 19:14:50

4K+ Views

In many programming languages, trying to access the element that is out of range of a string or list results in the IndexError. But Python behaves differently when it comes to substring slicing. Instead of generating the error, Python handles the out-of-range in slicing operations by adjusting the indices ... Read More

How to replace the last occurrence of an expression in a string in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 20-May-2025 13:33:55

8K+ Views

In this article, we are going to learn how to replace the last occurrence of an expression in a string. In Python, String manipulation is a common task, and Python provides the built-in method named replace(). Though we can replace the specified character or substring in a string using this method, ... Read More

Previous 1 ... 5 6 7 8 9 ... 38 Next
Advertisements