Python manages variable management as dict type.
It's important to manage it with a dict type.
a = "apple,banana,cow"
varTemplate = "print_{}"
for i, v in enumerate(a.split(',')):
globals()[varTemplate.format(i)] = v
print_0
Out[29]: 'apple'
print_1
Out[30]: 'banana'
print_2
Out[31]: 'cow'
a="apple,banana,cow"
print_1, print_2, print_3 = a.split(',')
print_1
Out[11]: 'apple'
print_2
Out[12]: 'banana'
print_3
Out[13]: 'cow'
© 2024 OneMinuteCode. All rights reserved.