Python
[Basic Grammar] Python Strings: Modify Strings
grace21110
2023. 10. 22. 12:03
반응형
- Upper Case
Example
The upper() method returns the string in upper case.
a = "Good Morning!"
print(a.upper())
- Lower Case
Example
The lower() method returns the string in lower case.
a = "Good Morning!"
print(a.lower())
- Remove Whitespace
Whitespace is the space before and/or after the actual text and if you want to remove it, you can use strip().
a = " Good Night! "
print(a.strip()) # returns "Good Night!"
- Replace String
If you want to replace a string, use replace().
a = "Hello, World!"
print(a.replace("H", "J"))
- Split String
The split() method returns a list where the text between the specified separator becomes the list items.
a = "Hello, World!"
print(a.split(",")) # returns ['Hello', ' World!']