
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
Found 10547 Articles for Python

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

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

279 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

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

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

933 Views
Here are some examples of how to delete a character from a string using Python. Using String Slicing One of the easiest ways to delete a character from a string in Python is to use string slicing. Here's how you can do it: Example In the first line of code, we define a string called "my_string" that contains the text "Hello World". In the second line of code, we remove the character "o" by creating a new string called "new_string". We do this by slicing the original string into two parts - the characters before the "o" and the ... Read More

882 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. Since computers store data as binary, converting the strings into binary helps to understand how data is stored or transmitted. Python provides several methods to achieve this. Using Python ord() and format() Functions The first approach is by using the Python ord() and format(), Where the Python ord() ... Read More