Answers for "how to initialize variables in python dynaimcally"

8

how to create dynamic variable names in python

for i in range(0, 9):
    globals()[f"my_variable{i}"] = f"Hello from variable number {i}!"


print(my_variable3)
# Hello from variable number 3!
Posted by: Guest on October-03-2020
1

python dynamic variable name

name = "a"
value = True
a_dictionary = {name: value}
print(a_dictionary["a"])
Posted by: Guest on November-02-2020

Code answers related to "how to initialize variables in python dynaimcally"

Python Answers by Framework

Browse Popular Code Answers by Language