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

Python String Functions Explained

The document provides a list of Python string functions along with examples and their outputs. Key functions include replace, count, upper, lower, title, capitalize, find, startswith, endswith, split, strip, and len. It also notes that strings are immutable and emphasizes storing the returned values from these functions.
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)
21 views2 pages

Python String Functions Explained

The document provides a list of Python string functions along with examples and their outputs. Key functions include replace, count, upper, lower, title, capitalize, find, startswith, endswith, split, strip, and len. It also notes that strings are immutable and emphasizes storing the returned values from these functions.
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

Python String Functions with Examples and Output

1. replace(old, new)
Example:
s = "hello world"
print([Link](" ", "-"))
Output:
hello-world

2. count(value)
Example:
s = "banana"
print([Link]("a"))
Output:
3

3. upper()
Example:
s = "python"
print([Link]())
Output:
PYTHON

4. lower()
Example:
s = "PYTHON"
print([Link]())
Output:
python

5. title()
Example:
s = "python is easy"
print([Link]())
Output:
Python Is Easy

6. capitalize()
Example:
s = "python is easy"
print([Link]())
Output:
Python is easy

7. find(value)
Example:
s = "computer"
print([Link]("p"))
Output:
3

8. startswith(value)
Example:
s = "python"
print([Link]("py"))
Output:
True
9. endswith(value)
Example:
s = "python"
print([Link]("on"))
Output:
True

10. split()
Example:
s = "python is easy"
print([Link]())
Output:
['python', 'is', 'easy']

11. strip()
Example:
s = " hello "
print([Link]())
Output:
hello

12. len()
Example:
s = "python"
print(len(s))
Output:
6

Note: Strings are immutable. Always store the returned value.

You might also like