Data Science Explorer

[Basic Grammar] Python Strings: Modify Strings 본문

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!']

 

'Python' 카테고리의 다른 글

Pandas Series  (0) 2023.10.26
Pandas  (0) 2023.10.25
[Basic Grammar] Python Strings: Slicing Strings  (1) 2023.10.22
[Basic Grammar] Python Strings  (1) 2023.10.22
[Basic Grammar] Python Arrays  (0) 2023.10.21