Python - remove a prefix from a string


Python tip (>=3.9):

You can use .removeprefix() to remove the prefix from a string.

For example, to remove a filename prefix:

invoice_filenames = ("INV_123.pdf", "INV_234.pdf", "INV_345.pdf")

for invoice_filename in invoice_filenames:
    print(invoice_filename.removeprefix("INV_"))

# 123.pdf
# 234.pdf
# 345.pdf