Convert string to variable name in python [duplicate] November 18, 2022 by Tarik x='buffalo' exec("%s = %d" % (x,2)) After that you can check it by: print buffalo As an output you will see: 2