Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
name1='jhonson'
i=1
print(name1) #give jhonson value
#another way
name(i)-->name1--->'jhonson' #but it is not working.
How to do with name,i variables combine to create name1 then get 'jhonson' value

What I have tried:

name1='jhonson'
i=1
print(name1) #give jhonson value
#another way
name(i)-->name1--->'jhonson' #but it is not working.
How to do with name,i variables combine to create name1 then get 'jhonson' value
Posted
Updated 8-Apr-21 1:38am

That makes no sense, the expression name(i) is a function call in Python. You cannot create, or refer to, variables in that way.
 
Share this answer
 
You cannot do (at least in a straightforward way) exactly what you are asking. However, a similar (very useful approach) is the one using lists. try, for instance
Python
name = ["foo","boo", "goo"] # a list of indexed variables...
print(name[1])
name[1]="jhonson"
print(name[1])
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900