Pythonトレーニング


4-3-1-1 文字列の変換

①lower, upper

w_str = "abcXYZ"
lower_str = w_str.lower()
print(lower_str)
->abcxyz

upper_str = w_str.upper()
print(upper_str)
->ABCXYZ

print(w_str)
->abcXYZ       # もとのまま

②replace

w_str = "abcXYZabc"
new_str = w_str.replace("abc", "aaa")
print(new_str)
->aaaXYZaaa

new_str = w_str.replace("abc", "aaa", 1)
print(new_str)
->aaaXYZabc