0% found this document useful (0 votes)
5 views2 pages

Python String rindex() Method Explained

The document provides an overview of Python string methods, which are built-in functions that operate on strings without altering the original string. It discusses various case-changing methods such as lower(), upper(), title(), swapcase(), and capitalize(), along with examples demonstrating their usage. Additionally, it explains the rindex() method, which returns the highest index of a substring within a string or raises a ValueError if the substring is not found.

Uploaded by

nigamks98
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Python String rindex() Method Explained

The document provides an overview of Python string methods, which are built-in functions that operate on strings without altering the original string. It discusses various case-changing methods such as lower(), upper(), title(), swapcase(), and capitalize(), along with examples demonstrating their usage. Additionally, it explains the rindex() method, which returns the highest index of a substring within a string or raises a ValueError if the substring is not found.

Uploaded by

nigamks98
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Greenwood High

Computer – String functions

Python string methods is a collection of in-built Python functions that operates on


strings.

Note: Every string method in Python does not change the original string instead returns
a new string with the changed attributes.

Python string is a sequence of Unicode characters that is enclosed in quotation marks.


In this article, we will discuss the in-built string functions i.e. the functions provided by
Python to operate on strings.

Case Changing of Python String Methods

The below Python functions are used to change the case of the strings. Let’s look at
some Python string methods with examples:

• lower(): Converts all uppercase characters in a string into lowercase


• upper(): Converts all lowercase characters in a string into uppercase
• title(): Convert string to title case
• swapcase(): Swap the cases of all characters in a string
• capitalize(): Convert the first character of a string to uppercase

Example: Changing the case of Python String Methods

# Python3 program to show the


# working of upper() function
text = 'geeKs For geEkS'

# upper() function to convert


# string to upper case
print("\nConverted String:")
print([Link]())

# lower() function to convert


# string to lower case
print("\nConverted String:")
print([Link]())

# converts the first character to


# upper case and rest to lower case
print("\nConverted String:")
print([Link]())

# swaps the case of all characters in the string


[Link]
# upper case character to lowercase and viceversa
print("\nConverted String:")
print([Link]())

# convert the first character of a string to uppercase


print("\nConverted String:")
print([Link]())

# original string never changes


print("\nOriginal String")
print(text)

Output
Converted String:
GEEKS FOR GEEKS

Converted String:
geeks for geeks

Converted String:
Geeks For Geeks

Converted String:
GEEkS fOR GEeKs

Original String
geeKs For geEkS

Python String rindex() method returns the highest index of the substring inside the
string if the substring is found. Otherwise, it raises ValueError.

Let’s understand with the help of an example:

s = 'geeks for geeks'


res= [Link]('geeks')
print(res)

Output
10

[Link]

You might also like