Tarun Chandra

Tarun Chandra

13 Articles Published

Articles by Tarun Chandra

Page 2 of 2

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

What are Python function attributes?

Tarun Chandra
Tarun Chandra
Updated on 18-Mar-2026 53 Views

In Python, everything is an object, and functions are no exception. Since functions are objects, they can have attributes — custom data attached to them, just like attributes on a class instance. This allows you to store metadata, counters, configuration, or any arbitrary data directly on a function. Function attributes are different from function parameters. Parameters are inputs passed during a function call, while attributes are persistent data stored on the function object itself. Syntax You can set and access function attributes using the dot (.) operator, or using setattr() and getattr() built-in functions − ...

Read More

How can I fill out a Python string with spaces?

Tarun Chandra
Tarun Chandra
Updated on 19-Oct-2022 12K+ 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