variable defining phyton | Sololearn: Learn to code for FREE!

+1

variable defining phyton

Hi How can we use the value of one variable as the name of another variable? for example nameST = input("please enter student name :") i want to create a list whose name is the variable value nameST nameST value that user enters fo nameST = []

6/7/2020 7:08:01 AM

nima rasi

16 Answers

New Answer

+3

Olivia nima x It's directly not possible, but you can do it like this πŸ‘‡ a=input("Enter a name :") d={a:[]} print(d[a])

+2

nima x your last 2 sentences I've not understood, plz explain it I think you want to do like this πŸ‘‡ nameST=input("Enter name :") nameST=[nameST] print(nameST)

+2

Olivia Don't forget to mention the name It makes confusion to whom are saying My code won't give any Error Type @ , a suggestion list will pop up choose a user to whom you want to mention

+2

Olivia You were saying about my code?

+2

Olivia It'll work everywhere

+1

I'm not entirely sure what it is your asking. I'd like to help but could you explain a bit better?

+1

πŠπ’π’π›π¨ π†π‘πšπ²πšπ₯ Sorry I misread. nima x To make a list you have to write: Name=[elements] If you do what Kiibo has said then the name of your list will be the value of nameST and so will the [0] element

+1

x=input() x=[x] print(x) This works

+1

Thanks @Kiibo Ghayal @Olivia

0

πŠπ’π’π›π¨ π†π‘πšπ²πšπ₯ Thanks Kiibo

0

πŠπ’π’π›π¨ π†π‘πšπ²πšπ₯ nameST=input("Enter name :") nameST=[nameST] what does this code do can you explain?

0

@πŠπ’π’π›π¨ π†π‘πšπ²πšπ₯ look here nameST = input("please enter name : ") # for example i enter john now i want to make a list john = []

0

Your welcome, I hope I was able to help a little ☺️

0

yes it helped me thank u so much @olivia

0

a=eval(input("enter your list:")) print(list(a)) I think this will work little bit

0

backup