+ 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 = []

7th Jun 2020, 7:08 AM
nima rasi
16 Answers
+ 3
Olivia [user id="16407163"]nima x[/user] It's directly not possible, but you can do it like this πŸ‘‡ a=input("Enter a name :") d={a:[]} print(d[a])
7th Jun 2020, 7:26 AM
Prince Kumar
Prince Kumar - avatar
+ 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)
7th Jun 2020, 7:15 AM
Prince Kumar
Prince Kumar - avatar
+ 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
7th Jun 2020, 7:18 AM
Prince Kumar
Prince Kumar - avatar
+ 2
Olivia You were saying about my code?
7th Jun 2020, 7:20 AM
Prince Kumar
Prince Kumar - avatar
+ 2
Olivia It'll work everywhere
7th Jun 2020, 7:30 AM
Prince Kumar
Prince Kumar - avatar
+ 1
I'm not entirely sure what it is your asking. I'd like to help but could you explain a bit better?
7th Jun 2020, 7:14 AM
Olivia
Olivia - avatar
+ 1
πŠπ’π’π›π¨ π†π‘πšπ²πšπ₯ Sorry I misread. [user id="16407163"]nima x[/user] 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
7th Jun 2020, 7:24 AM
Olivia
Olivia - avatar
+ 1
x=input() x=[x] print(x) This works
7th Jun 2020, 7:29 AM
Olivia
Olivia - avatar
+ 1
Thanks @Kiibo Ghayal @Olivia
7th Jun 2020, 7:35 AM
nima rasi
0
πŠπ’π’π›π¨ π†π‘πšπ²πšπ₯ nameST=input("Enter name :") nameST=[nameST] what does this code do can you explain?
7th Jun 2020, 7:21 AM
nima rasi
0
@πŠπ’π’π›π¨ π†π‘πšπ²πšπ₯ look here nameST = input("please enter name : ") # for example i enter john now i want to make a list john = []
7th Jun 2020, 7:24 AM
nima rasi
0
Your welcome, I hope I was able to help a little ☺️
7th Jun 2020, 7:35 AM
Olivia
Olivia - avatar
0
yes it helped me thank u so much @olivia
7th Jun 2020, 7:37 AM
nima rasi
0
a=eval(input("enter your list:")) print(list(a)) I think this will work little bit
8th Jun 2020, 8:17 AM
γ€ŠA$# β˜† $ING#》
γ€ŠA$# β˜† $ING#》 - avatar
0
backup
9th Jun 2020, 4:41 AM
Harri