Apr-19-2021, 07:11 AM
Thanks Yoriz for pointing out the issue.
Another solution seems to use globals() function as a dictionnary (key + value)
Another solution seems to use globals() function as a dictionnary (key + value)
Sentence = "World is " print("without using a function") Add0 = 'beautifull' exec("New0 = Sentence + '%s'" %Add0) print("\t- Complete sentence 0 = {}".format(New0)) print("\nUsing a function") def Complete(Part): Add = 'beautifull' globals()["New"] = Part + Add print("\t- Complete sentence 1 = {}".format(New)) print("\t- Complete sentence 2 = %s" %(New)) Complete(Sentence)
Output:without using a function
- Complete sentence 0 = World is beautifull
Using a function
- Complete sentence 1 = World is beautifull
- Complete sentence 2 = World is beautifull