0% found this document useful (0 votes)
8 views1 page

Python String Methods Summary

This document summarizes various Python string methods, including their descriptions and examples. Key methods include lower(), upper(), capitalize(), and split(), among others. Each method is designed to perform specific operations on string data, such as changing case, trimming whitespace, and finding substrings.

Uploaded by

kebalimad30
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)
8 views1 page

Python String Methods Summary

This document summarizes various Python string methods, including their descriptions and examples. Key methods include lower(), upper(), capitalize(), and split(), among others. Each method is designed to perform specific operations on string data, such as changing case, trimming whitespace, and finding substrings.

Uploaded by

kebalimad30
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
You are on page 1/ 1

Python String Methods Summary

Method Description & Example

lower() Converts to lowercase: "HELLO".lower() -> "hello"

upper() Converts to uppercase: "hello".upper() -> "HELLO"

capitalize() Capitalizes first letter: "python".capitalize() -> "Python"

title() Capitalizes each word: "hello world".title() -> "Hello World"

strip() Trims whitespace: " hello ".strip() -> "hello"

lstrip()/rstrip() Trims whitespace on left/right

replace(old, new) "apple".replace("p", "b") -> "abble"

split(sep) "a,b,c".split(",") -> ['a', 'b', 'c']

join(list) ",".join(['a', 'b', 'c']) -> "a,b,c"

find(sub) "banana".find("a") -> 1

index(sub) Like find() but raises error if not found

startswith(sub) "hello".startswith("he") -> True

endswith(sub) "data.txt".endswith(".txt") -> True

count(sub) "banana".count("a") -> 3

isalpha() "abc".isalpha() -> True

isdigit() "123".isdigit() -> True

isalnum() "abc123".isalnum() -> True

isspace() " \t".isspace() -> True

islower()/isupper() Check if all letters are lowercase/uppercase

You might also like