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 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 MoreWhat are Python function attributes?
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 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