Python String methods help manipulate and analyze text data. These include lower(), upper(), replace(), strip(), split(), and join(). These allow you to clean, transform, and extract information from the text data effectively.
Table of contents

Python String Methods
Here is a list of the Python string methods mentioned in the provided content:
find: Returns the index of a substring within a string.upper: Converts a string to uppercase.lower: Converts a string to lowercase.strip: Removes specified characters from the beginning and end of a string.replace: Replaces a portion of a string with a new string.split: Splits a string into a list of substrings.join: Joins elements of a list into a single string.in: Checks if a character or substring is present in a string.not in: Checks if a character or substring is not present in a string.endswith: Checks if a string ends with a specified substring.
These methods can be helpful in various data analytics projects.
find
The Python string find function provides an index for substring.
a="my own string"
b=a.find('own')
print(b)
Result: 3 (index)
upper
The upper function in Python converts string to upper case.
a="my own string"
b=a.upper()
print(b)
Result: MY OWN STRING (converts to upper case)
lower
The lower method in Python converts the string to lowercase.
a="my OWN string"
b=a.lower()
print(b)
Result: my own string (converts to lower)
strip
The strip function in Python strips a portion from the string.
a="my Own String"
b=a.strip('my')
print(b)
Resut: Own String (it strips only edges)
replace
The Python replace and replace all methods are used to substitute an existing string with a new string.
a="my Own String"
b=a.replace('my', 'This is')
print(b)
Result: This is Own String (it replaces a portion of string)
split
The split function in Python divides strings into lists.
a = 'My Own String'
b= a.split()
print(b)
Result: ['My', 'Own', 'String']
join
Check out how to use the join method in Python.
in
The in and not in operators in Python are used to check if a character or string is present in another string.
a = 'My Own String'
b= 'My' in a
print(b)
Result : True
not in
a = 'My Own String'
b= 'My' not in a
print(b)
Result: False
endswith
The Python code checks if a string ends with a specific portion.
a = 'My Own String'
b= a.endswith('String')
print(b)
Result: True
Related







You must be logged in to post a comment.