In Python 3, is there a way to concatenate a string/variable to a(nother) variable?
Say I have a some variables with similar names (for simplicity sake, they are variable; in actuality, I want to do it with class & objects):
var1 = 'Hello'
var2 = 'Greetings'
The user inputs a number, and the script prints using else if statements:
choice = input("Please select a number (1-2) >")
if choice = 1:
print(var1)
elif choice = 2:
print(var2)
But what I want to do is print directly without having to use else if/ switch statements/dictionaries etc. I want it so it prints(var+choice)
, where choice would concatenate to var, so if choice = 1, it would be print(var1)
; and if choice = 3, it would print(var3)
(which would give an error, undefined variable).
If there isn't a way to do this, what is the cleanest way to print a choice of variables that have similar names?