Tarun Chandra has Published 61 Articles

How to find the nth occurrence of substring in a string in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 10:15:37

4K+ Views

In this article, we are going to find out how to find the nth occurrence of a substring in a string in Python. The first approach is by using the split() method. We have to define a function with arguments as string, substring, and the integer n. By dividing at ... Read More

How to convert a Python csv string to array?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 10:13:16

12K+ Views

In this article, we are going to find out how to convert a CSV string into an array. The first approach is by using the split() method. This method takes a parameter, and delimiters the character at which the string should be split. Since the input is a csv, which ... Read More

How to remove a list of characters in string in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 10:10:35

4K+ Views

In this article, we are going to find out how to remove a list of characters in string in Python. The first approach is by using the replace() method. This method takes 2 parameters, the character we would like to replace and the character with which we are replacing. This ... Read More

How to get integer values from a string in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 10:05:47

9K+ Views

In this article, we are going to find out how to get integer values from a string in Python. The first approach is by using the filter() method. We will pass the string and the method isdigit() to the filter method. Python has a built-in function called Filter(). An iterable, ... Read More

How to extract date from a string in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 10:01:57

13K+ Views

In this article, we are going to find out how to extract a date from a string in Python. Regular expressions are used in the first technique. Import the re library and install it if it isn't already installed to use it. After importing the re library, we can use ... Read More

How to scan a string for specific characters in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 09:15:26

3K+ Views

In this article, we are going to find out how to scan a string for specific characters in Python. The first approach is by using the ‘in’ keyword. We can use the ‘in’ keyword for checking if a character is present in the string. If it is present in the ... Read More

How to find the longest common substring from more than two strings in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 09:13:06

1K+ Views

In this article, we are going to find the longest common substring from more than two strings in Python. The first and only approach for finding the longest common substring is by using the Longest common substring Algorithm. We will define a function that accepts 2 strings, then we will ... Read More

How to check if a string can be converted to float in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 09:10:29

1K+ Views

In this article, we are going to focus on checking if a string can be converted to a float in Python. The first approach is by using the float() type cast. We will write a function using exception handling and check if the given string can be converted into string, ... Read More

How to remove all special characters, punctuation and spaces from a string in Python?

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 09:03:12

5K+ Views

In this article, we are going to find out how to remove all special characters punctuation and spaces from a string in Python. The first approach is by using isalnum() method on each character of the string by iterating it using for loop. We will check if each character is ... Read More

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

Tarun Chandra

Tarun Chandra

Updated on 07-Dec-2022 09:00:08

3K+ Views

In this article, we are going to find out how to extract a substring from inside a string in Python. The first approach is by using Regular expressions. A string of characters that creates a search pattern is known as a regex, or regular expression. RegEx can be used to ... Read More

Advertisements