The document contains Python code snippets demonstrating various string manipulation methods such as capitalization, counting substrings, and checking string endings. Each snippet shows a different function applied to strings, including padding and finding substrings. The examples illustrate practical uses of string methods in Python programming.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views1 page
Python Revision 1 and 2
The document contains Python code snippets demonstrating various string manipulation methods such as capitalization, counting substrings, and checking string endings. Each snippet shows a different function applied to strings, including padding and finding substrings. The examples illustrate practical uses of string methods in Python programming.
7 s = "hello world" 8 s = "Python is fun and Python is powerful."
res = s.count("o") print(s.count("Python")) print(res) 9 s = "apple banana apple grape apple" 10 s = "apple banana apple grape apple" substring = "apple" substring = "apple" res = s.count(substring, 1, 20) res = s.count(substring, 8, 20) print(res) print(res) 11. string = "geeksforgeeks" 12 text = "geeks for geeks." print(string.endswith("geeks")) result = text.endswith('geeks.', 10) print(result) 13 text = "geeks for geeks." 14 s = "Welcome to GeekforGeeks!" result = text.endswith('geeks.', 10,16) index = s.find("GeekforGeeks") print(result) print(index) 15