[Solved] How to assign anything to input string? | SoloLearn: Learn to code for FREE!

+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?

5/23/2020 8:30:01 PM

Jslearn

15 Answers

New Answer

+5

Show your attempts.

+5

Pylearn if we do t know, what we entered, https://code.sololearn.com/cMSsZdDDoTk3/?ref=app

+3

https://code.sololearn.com/cMSsZdDDoTk3/?ref=app

+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.

+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.

+2

rodwynnejones apparently not, but i want to convert string to identifier.

+2

Is this what you need? globals()[input()]=25 print(z) https://www.codespeedy.com/convert-string-into-variable-name-in-python/

+2

comment/code deleted...as...on second thoughts......, I don't think it's what your looking to do

+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.

+2

Is this what you want? https://code.sololearn.com/c01nz99jMPSY/?ref=app

+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?

+2

Valmob101 thanks understood!!

+2

Answers: Valmob101 https://code.sololearn.com/cTqRIMq9F46o/?ref=app Oma Falk https://code.sololearn.com/cR6I8zbCoAnF/?ref=app

+1

Is this what your trying to do?:- mystring1 = input() + 't' print(mystring1) # or... mystring2 = input() mystring2 += 't' print(mystring2)

+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