Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Articles - Page 1031 of 1048
18K+ 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 task. In this article we will explore the different ways to extract dates from the strings. Using the Python "re" Module The python re module supports regular expressions, helping in string pattern matching and manipulation. In this approach, we are going to use the regular expression pattern to ... Read More
4K+ 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 string, True is returned otherwise, False is returned. The ‘in’ keyword is also used to iterate through a sequence in a for loop which is also used for iterating over a sequence like list, tuple and string or other iterable objects. Example 1 In the example given below, we are ... Read More
2K+ Views
The substrings are the sequence of characters that appear within the string. While working with multiple strings, it is useful to find the longest common substring. There are various ways to find the longest common substring from more than two strings. one of the most common approach is using the dynamic programming. Let's dive into the article to learn more about this task. Using Dynamic Programming In this approach, we are going to use the dynamic programming (DP), Here we compare the strings pairwise (starting with first two strings), we find their longest common substring using a DP ... Read More
2K+ 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, if it can be converted then True is returned, else False is returned. A floating−point number is returned by the method float() for a given number or text. It will return 0.0 as the floating−point value if no value or a blank parameter is given. Example 1 In this example, ... Read More
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 given string. For performing this task, Python provides built-in features. Using Suffix Array and LCP A suffix array is used to store all the suffixes of the given string in lexicographic order. In this approach, we will consider the input string and create a list of all ... Read More
7K+ Views
It is necessary to clean up the strings by removing the unwanted elements such as special characters, punctuation, and spaces. These unwanted characters can be involved in the tasks and cause unexpected results. In this article, we are going to learn more about removing all special characters, punctuation and spaces from a string. Using Python re Module Through the re module, Python provides support for regular expressions. This module contains methods and classes that we can search, match, and modify a string (text content) using regular expressions.ThePython re.sub() method accepts a pattern, a replacement string, and a string as ... Read More
312 Views
The preferred way to concatenate a string in Python is by using the + operator or the join() method. Here's a step-by-step explanation of each method − Using the + operator To concatenate two strings using the + operator, simply put the strings next to each other with a + sign in between them. Example In this example, we concatenate the name variable with the greeting string using the + operator. The resulting string is "Hello, John!". name = "John" greeting = "Hello, " + name + "!" print(greeting) Output Hello, John! Using multiple + operators You ... Read More
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 into the article to learn more about extracting the substring from the string. Using Python slicing The first approach is by using the Python slicing, It is the most common way to extract the substrings. Simply, we require the start and end indices. Example In the following example, ... Read More
32K+ 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 before using the string methods like upper(), lower(). If the variable is not of the expected type, calling these methods will raise an error. Python provides various ways to check if the variable is of type string. Let's dive into the article to learn more about it. ... Read More
11K+ 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 one - Using Python str.isdigit() Method The first approach is by using the Python isdigit() method. It is used to check whether the character is a digit. It returns true if all the characters in the input string are digits. Syntax Following is the syntax for Python str.isdigit() ... Read More