Mastering Python String Modifying
Mastering Python String Modifying
Python
Modify
Strings
resources: www.w3schools.com
01
Python Modify Strings
Python has a set of built-in methods that you can use on
strings.
Upper Case
The upper() method returns the string in upper case:
a = "Python, World!"
print(a.upper())
Result:
PYTHON, WORLD!
Lower Case
The lower() method returns the string in lower case:
a = "Python, World!"
print(a.lower())
Result:
python, world!
2
The strip() method removes any whitespace from the beginning
or the end:
a = " Python, World! “
print(a.strip())
Result:
Python, World!
Replace String
The replace() method replaces a string with another string:
a = " Python, World! “
print(a.replace(“o”, “a”))
Result:
Pythan, Warld!
I Learn to Code
@ilyasqasim
resources:
www.w3schools.com