Yaswanth Varma has Published 308 Articles

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

7K+ 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

How to convert string to binary in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 20-May-2025 13:15:34

878 Views

In this article, we are going to learn about converting a string to binary, which means representing each character in the string using the binary digits 0 and 1. A binary number is a number expressed in the base2 numerical system, which uses only two symbols - 0 and 1. ... Read More

How to correctly sort a string with a number inside in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 20-May-2025 13:12:58

3K+ Views

Sorting the string that contains the number, such as ("xy1", "xy2", "xy10"),  can be complex in Python. For example, if we sort the list ["xy1", "xy2", "xy10"] using the built-in sort() method, it results in ["xy1", "xy10", "xy2"]. But we will expect "xy2" to come before "xy10". It is ... Read More

How to wrap long lines in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 20-May-2025 13:01:25

22K+ Views

In Python, we will come across situations where we encounter long lines of code that exceed the recommended line length of 79 characters (suggested by the Python style guide). To improve code readability, Python provides several ways to wrap long lines. In this article, we will explore the various methods ... Read More

How can I test if a string starts with a capital letter using Python?

Yaswanth Varma

Yaswanth Varma

Updated on 20-May-2025 12:57:53

15K+ Views

A string is a collection of characters that can represent a single word or a whole sentence. Unlike Java, there is no need to declare Python strings explicitly; we can directly assign a string value to a literal. While working with the string, we will encounter situations to check ... Read More

How to concatenate a string with numbers in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 20-May-2025 12:54:53

7K+ Views

Concatenation is nothing but the process of joining two or more strings together. In Python, if one value is a number (integer or float), we can't directly concatenate it with a string using the '+' operator, as it raises a TypeError. Python does not allow the implicit conversion between ... Read More

How to remove characters except digits from string in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 20-May-2025 12:51:48

10K+ Views

While working with the texts in Python, we will find the strings that contain a mix of characters such as letters, digits, and white-space. In some scenarios, we may need to extract only the numeric digits from such strings. For achieving this, Python provides various ways. Let's explore one by ... Read More

How to check if type of a variable is string in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 20-May-2025 11:51:21

31K+ Views

In this article, we are going to find out how to check if the type of a variable is a string in Python. It is necessary to verify the type of a variable before performing the operations. For example, if we want to ensure that the variable is a string ... Read More

How to extract a substring from inside a string in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 20-May-2025 11:44:44

4K+ Views

In programming, a substring is a smaller part of the string. Extracting the substring is a task in Python, whether we are analysing the user input or manipulating URLs, we will find ourself to grab a portion of the string. For achieving, Python provides the various way, Let's dive ... Read More

How to extract date from a string in Python?

Yaswanth Varma

Yaswanth Varma

Updated on 20-May-2025 11:41:54

17K+ Views

In Python, Extracting dates from the strings is the common task in the data preprocessing and text analysis, especially when dealing with user inputs. Dates can appear in many formats like DD-MM-YYYY, YYYY/MM/DD or in text formats like April 25, 2025. Python offers various libraries and tools to achieve this ... Read More

1 2 3 4 5 ... 31 Next
Advertisements