Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

variable bound to set python

"""
Through the globals() function, one can bind a variable to a set as illustrated below. 
name str variable was both bound to different sets and used to modify these sets. 
"""
name = "set"
set1 = set()
set2 = set()
set3 = set()

for i in range(1, 4): 
	globals()[name + str(i)].add(i)  # access ith set and add value of i to it

print(set1)  # {1}
print(set2)  # {2}
print(set3)  # {3}
 
PREVIOUS NEXT
Tagged: #variable #bound #set #python
ADD COMMENT
Topic
Name
8+5 =