- 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
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
+ 2
What about this one
https://code.sololearn.com/c6RkMQVlP2n7/?ref=app
+ 1
https://code.sololearn.com/cJw8Z7EzJE0m/?ref=app
Like this
0
You mean to concatenate?
0
Atul yes
expected output is "hello world"
0
I think so you have got your answer in comments
0
Atul nope
read the note : I need without using eval()
0
b="world"
a="hello"
x=a+" "+b
print(x)
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.