Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Tarun Chandra
Page 2 of 2
How to split at NEWLINEs in Python?
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 MoreHow to search a string in backwards direction in Python?
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 MoreHow can I fill out a Python string with spaces?
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