-2

I am wondering if we can use a variable name in order to create a new variable, for example:

Let's assume I have this variable:

 Var = 'Jim'

Lets say I want to concatenate the variable with a string, in this case the string is the word Mr:

 NewVar = "String"Var

So that if I print the new variable, the output would look something like:

 MrJim

This can be achieved in bash like this:

 NewVar=Mr${Var}

But I have not found a way to do this in Python. Please let me know if you know how to do it.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0

Have a look at python string interpolation.

var = "Jim"
new_var = f"Mr {var}"
botchniaque
  • 4,698
  • 3
  • 35
  • 63