How do you convert string as a variable name in python?
Answer / Nirbhay Narayan Pandey
In Python, you can use the 'globals()' or 'locals()' functions to get a dictionary of current global and local symbol table (variable names). Then, you can use the dictionary to create or access variables using strings. Here's an example:
my_var = 10
var_name = 'my_var'
print(globals()[var_name]) # Outputs: 10
| Is This Answer Correct ? | 0 Yes | 0 No |
Explain Inheritance in Python?
What happens if an error occurs that is not handled in the except block?
What are the steps required to make a script executable on Unix?
What is the optional statement used in a try except statement in Python?
What does sorted do in python?
What are variables in python?
How many basic types of functions are available in python?
What is flask- wtf? Explain its features.
What is range() in python?
What is the statement that can be used in python if the program requires no action but requires it syntactically?
Tell me the use of // operator in python?
Does python have polymorphism?