Say i want to declare a string for my entire class to use, but that string has a part that might change later. Is it possible to only have to declare the string once, and "refreshing" it later?
Example:
substring = ""
my_long_string = f"This is a long string using another {substring} in it."
def printMyString(newString):
substring = newString
print(my_long_string)
printMyString(newString="newer, better substring")
Can i adjust this code so that in the end, it prints out This is a long string using another newer, better substring in it., without declaring the long string again later on?
My only guess would be something like this:
substring = ""
def regenerate_string(substring):
return f"This is a long string using another {substring} in it."
def printMyString(newString):
print(regenerate_string(newString))
printMyString(newString="newer, better substring")
But i want to ask if there possibly is a built-in function in Python to do exactly that?