Sorry, i didn't notice the
See this link
exec("New = Part + '%s'" %Add)
.See this link
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' ldict = locals() exec("New = Part + '%s'" %Add,globals(),ldict) New = ldict['New'] 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