I have these initializations:
countrys = []
codes = []
index_countrys = {}
index_codes = {}
I want to declare them at once like this:
countrys,codes = []
index_countrys,index_codes = {}
Is that allowed in Python?
I have these initializations:
countrys = []
codes = []
index_countrys = {}
index_codes = {}
I want to declare them at once like this:
countrys,codes = []
index_countrys,index_codes = {}
Is that allowed in Python?
You can use:
countries, codes = [], []
index_countries, index_codes = {}, {}
or even :
countries, codes, index_countries, index_codes = [], [], {}, {}
This is a good way to set multiple variables to distinct values using only a single line of code.
Searching āpython set multiple variables site:stackoverflow.comā will give you many other options and recommendations on which ones to use.
Yes, you can!
On python you can declare chained vars with equals sign. Just like that:
countrys = codes = []
index_countrys = index_codes = {}