- 1

how to print the variable value from input ?

Note : without using eval() or exec() input : ab expected output : hello world my attempt : https://code.sololearn.com/c9BDjoOJwcbT/?ref=app

3rd Feb 2021, 2:46 PM
Ratnapal Shende
Ratnapal Shende - avatar
9 Réponses
+ 6
Ratnapal Shende Use dictionaries. See this example https://code.sololearn.com/cU7hgFe7tnqC/?ref=app Or, if you want to use it with variables defined in the global scope, the globals() function returns a dictionary having all the variables stored with their values https://code.sololearn.com/cMDZrKCnbTyV/?ref=app
3rd Feb 2021, 3:20 PM
XXX
XXX - avatar
3rd Feb 2021, 4:25 PM
K.S.S. Karunarathne
K.S.S. Karunarathne - avatar
+ 1
https://code.sololearn.com/cJw8Z7EzJE0m/?ref=app Like this
3rd Feb 2021, 3:21 PM
Atul [Inactive]
0
You mean to concatenate?
3rd Feb 2021, 3:02 PM
Atul [Inactive]
0
Atul yes expected output is "hello world"
3rd Feb 2021, 3:12 PM
Ratnapal Shende
Ratnapal Shende - avatar
0
I think so you have got your answer in comments
3rd Feb 2021, 3:15 PM
Atul [Inactive]
0
Atul nope read the note : I need without using eval()
3rd Feb 2021, 3:17 PM
Ratnapal Shende
Ratnapal Shende - avatar
0
b="world" a="hello" x=a+" "+b print(x)
3rd Feb 2021, 4:49 PM
**🇦🇪|🇦🇪**
**🇦🇪|🇦🇪** - avatar
0
Try making x a list x = [a, b] Then your loop executes. Output: ["hello", "world"] If you want it to be printed as a string, the join() method comes in handy. Syntax: (" ".join(sen)) Note the space in the quote. Hope this helps.
4th Feb 2021, 12:29 PM
Fatunmbi Teniola