Python: sub Function
Posted: Sat Aug 16, 2025 2:54 pm
Code: Select all
import re
band_name = "Shocking Green"
print(band_name)
new_band_name = re.sub("Green", "Blue", band_name)
print(new_band_name)
# prints out "Shocking Blue"
Code: Select all
import re
band_name = "Shocking Green"
print(band_name)
new_band_name = re.sub("Green", "Blue", band_name)
print(new_band_name)
# prints out "Shocking Blue"