+ 1

[Solved] How to assign anything to input string?

[Changed context] I have a variable 'a' with an input. #a = input() #say input is "t" Then the below code should be like that which will assign "t"(based on input) to "abc"(string), concatenate "d" to "abc" and print the output. #output= abcd Is it possible?

23rd May 2020, 8:30 PM
Jslearn
15 Answers
+ 5
Show your attempts.
23rd May 2020, 8:31 PM
A͢J
A͢J - avatar
+ 5
24th May 2020, 5:43 AM
Oma Falk
Oma Falk - avatar
+ 3
https://code.sololearn.com/cMSsZdDDoTk3/?ref=app
23rd May 2020, 8:45 PM
Oma Falk
Oma Falk - avatar
+ 3
Pylearn locals and vars are same except vars can take an optional argument as a class, object, instance which as __dict__ attribute and returns it. Either way if no argument is passed to vars it will act same like locals.
24th May 2020, 6:11 AM
Lerninn
+ 2
Pylearn If you write anything inside double quotes that will be String not variable. We assign value to variable not any String. Do like this #input is z a = input() a = 5 print(a) but it doesn't make sense we can directly take 5 from input.
23rd May 2020, 8:40 PM
A͢J
A͢J - avatar
+ 2
rodwynnejones apparently not, but i want to convert string to identifier.
23rd May 2020, 9:17 PM
Jslearn
+ 2
Is this what you need? globals()[input()]=25 print(z) https://www.codespeedy.com/convert-string-into-variable-name-in-python/
23rd May 2020, 9:37 PM
Abhay
Abhay - avatar
+ 2
comment/code deleted...as...on second thoughts......, I don't think it's what your looking to do
23rd May 2020, 10:38 PM
rodwynnejones
rodwynnejones - avatar
+ 2
Abhay thanks, you solved string assigning one. But how to print it when you don't know the input. As you wrote"print(z)" but what if we don't know that we gonna input z. It could be any random string.
24th May 2020, 3:15 AM
Jslearn
24th May 2020, 5:37 AM
Lerninn
+ 2
Valmob101 Oma Falk yes i want this, thanks. I don't know how this works but excellent for my task. vars vs locals what is good?
24th May 2020, 5:47 AM
Jslearn
+ 2
Valmob101 thanks understood!!
24th May 2020, 6:22 AM
Jslearn
+ 1
Is this what your trying to do?:- mystring1 = input() + 't' print(mystring1) # or... mystring2 = input() mystring2 += 't' print(mystring2)
23rd May 2020, 9:12 PM
rodwynnejones
rodwynnejones - avatar
+ 1
I'm not sure I fully understand you. This is my attempt, I hope it is what you are looking for. Pylearn https://code.sololearn.com/c71JBAMk98j7/?ref=app
23rd May 2020, 9:44 PM
Josshual A. Toro M.
Josshual A. Toro M. - avatar