Tarun Chandra

Tarun Chandra

13 Articles Published

Articles by Tarun Chandra

Page 2 of 2

How to split at NEWLINEs in Python?

Tarun Chandra
Tarun Chandra
Updated on 24-Mar-2026 32K+ Views

In Python, splitting strings at newlines is a common text processing task. Python provides two main approaches: the splitlines() method and the split() method with '' parameter. Using splitlines() Method The splitlines() method is specifically designed for splitting strings at line breaks. It handles various types of line endings automatically and doesn't require any parameters ? Example 1 Splitting a string with escape sequence newlines ? text = "WelcometoTutorialspoint" print("The given string is:") print(text) print("The resultant string split at newline is:") print(text.splitlines()) The given string is: Welcome to Tutorialspoint ...

Read More

How to search a string in backwards direction in Python?

Tarun Chandra
Tarun Chandra
Updated on 24-Mar-2026 4K+ Views

In this article, we are going to find out how to search a string in backward direction in Python. Python provides two main methods for searching strings from right to left: rindex() and rfind(). Both methods find the rightmost occurrence of a substring but handle missing substrings differently. Using rindex() Method The rindex() method returns the highest index of any substring in the given string. By highest index, we mean that if a substring appears multiple times, rindex() returns the index of the rightmost occurrence. The main disadvantage is that it throws a ValueError if the ...

Read More

How can I fill out a Python string with spaces?

Tarun Chandra
Tarun Chandra
Updated on 19-Oct-2022 13K+ Views

A string is a collection of characters that can represent a single word or a whole sentence. Unlike other technologies there is no need to be declared strings in Python explicitly we can define a string with or without the datatype specifier. A string in Python is an object of the String class, which contains multiple methods using which you can manipulate and access strings. In this article we are going to discuss fill out a Python string with spaces. Let’s see various solutions one by one. Using the ljust(), rjust() and center() methods To pad the string with desired ...

Read More
Showing 11–13 of 13 articles
« Prev 1 2 Next »
Advertisements