0% 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.

Uploaded by

svvsuganyacbse
Copyright
© © All Rights Reserved
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% 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.

Uploaded by

svvsuganyacbse
Copyright
© © All Rights Reserved
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
You are on page 1/ 1

1 s = "hello WORLD" 2 s = "multiple WORDS IN a String"

res = s.capitalize() res = s.capitalize()


print(res) print(res)
3 s = "123hello WORLD" 4 string = "GEEKSFORGEEKS"
res = s.capitalize() print("lowercase string: ",
print(res) string.casefold())

5 string = "geeks for geeks" 6 string = "geeks for geeks"


new_string = string.center(24) new_string = string.center(24, '#')
print("After padding String print("After padding String is:",
is: ", new_string) new_string)

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

You might also like