
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 10548 Articles for Python

9K+ Views
Strings are one of the most commonly used data types. In this article, we are going to find out how to convert a string to a list of words in Python. Converting the string into a list is helpful when dealing with user inputs or when we want to manipulate individual words in a string. Python provides several ways to achieve this. Let's explore them one by one. Using Python str.split() Method Python str.split() method accepts a separator as a parameter, splits the string at the specified separator, and returns the result as a list. If we use the split() ... Read More

6K+ Views
A string is a collection of characters that may be used to represent a single word or an entire phrase. Strings are useful in Python since they don't need to be declared explicitly and may be defined with or without a specifier. In this article, we are going to find out how to split a multi-line string into multiple lines in Python. While working with the strings in programs, we will come across multi-line strings. To process such strings one by one, we need to split the string into individual lines. In this article, we will explore different methods. ... Read More

1K+ Views
In this article, we are going to find out how to remove a substring from the end of a string in Python. The first approach is by using slicing approach. In this method, we will check if the string is ending with the given substring or not, if it is ending with the given substring then we will slice the string, removing the substring. The ability to access portions of sequences like strings, tuples, and lists in Python is known as slicing. Additionally, you can use them to add, remove, or edit the elements of mutable sequences like lists. Slices ... Read More

1K+ Views
In this article, we are going to find out how can we tell if a string repeats itself in Python. The first approach is by using slicing and find(). We want to see if the string we have is made up entirely of repeats of a substring of the string. We can confirm this by looking for a rotation of the string in a pair of strings. After adding a string and checking the root string in this string, except for the last and first character, we may search for the root string. This approach doesn’t work for strings with ... Read More

2K+ Views
In this article, we are going to find out how to do string concatenation without the plus operator in Python. Generally, String concatenation is the process of joining two or more strings into one, and the common way to do this is by using the '+' operator. For example, writing "Welcome" + " " + "TP" results in the string "Welcome TP". But here we need to perform the concatenation without the '+' operator. For achieving this, Python provides alternative methods, which we will explore one by one. Using Python join() Method The first approach is ... Read More

4K+ Views
You can perform some math operations on Python strings technically, but it may not work the way you expect it to. Here are a few examples: Concatenating Strings with + Example In this example, we concatenate two strings by using the + operator. This works because the + operator is overloaded in Python to work with strings as well as numbers. When we use the + operator with strings, it concatenates them together to form a single string. string1 = "Lorem " string2 = "Ipsum" result = string1 + string2 print(result) Output Lorem Ipsum Multiplying Strings with * ... Read More

5K+ Views
While working with the strings, the common requirement is searching for a specific substring within a larger string. Python provides built-in methods that allow you to locate the first occurrence of a substring. But what if the substring appears multiple times. For example, consider the string "Welcome to the Tutorialspoint to". If we look for the second occurrence of the substring "to", using the find() will get only the first match, but we need an approach that searches beyond the first occurrence, counting each one until the nth. In this article, we will explore how to find the nth ... Read More

16K+ Views
The comma-separated values (CSV) is a text format that is used for storing tabular data. In Python, we will come across situations where CSV data is available in string format. For performing operations on this data, we need to convert it into an array. Python provides multiple ways to achieve this conversion. In this article, we are going to learn about converting the CSV string into an array. Using Python split() Method In this approach, we are going to use the Python split() method, which is used to split all the words in a string separated by ... Read More

5K+ Views
In Python, Strings are the immutable sequences of characters. While working with them, we will come across situations where we need to remove the unwanted characters (like punctuation, special symbols, etc.). In this article, we are going to find out how to remove a list of characters from a string. Python provides several ways to achieve this using the built-in methods and list comprehensions. Using Python str.replace() Method The python str.replace() method is used to replace all occurrences of one substring in a string with another substring. This method takes 2 parameters: the character ... Read More

12K+ 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, like a list or dictionary, can have the filter function applied to it to create a new iterator. Based on the criteria you provide, this new iterator can filter out specific elements quite well. The filter() method checks the string for digits and filters out the characters that satisfy the ... Read More