I want to declare a variable according to the number of elements in array A (which changes dynamically) and put elements in the declared variable as shown below.
A = ['a','b','c','d'] num1 = a num2 = b num3 = c num4 = d
Instead of manually defining this as num1 = A , num2 = A  ..., variables (num1, num2 ...) are automatically generated according to the number of elements in array A. , I want to store the elements of array A there.
It was difficult to find out, so I asked a question.
I would appreciate it if you could give me some advice.
Answer # 1
A = ['a','b','c','d'] for i in range (len (A)): exec ('num' + str (i + 1) +'= A [i]') print (num1) # a
- python sarimax how to input exogenous variables (error check request)
- handling of python variables
- python - how to break the contents of list format variables one by one and output to a file?
- about variables in python
- python - what dijkstra's algorithm variables represent
- python - variables cannot be defined
- python's convention for naming variables such as `list`,` dict`
- i want to dynamically change the value of a variable in python and execute it
- python - batch multiple declaration i want to declare multiple characters at once as a character string
- python - how to change sequential variables during string search loop processing
- put the maximum value of the list of variables in the objective function with python pulp
- what is the difference between environment variables in python and environment variables that can be seen in system-> system
- python 3x - what is the best place to declare functions and classes in python?
- python 3x - i can't use pyinstaller, and when i try to set environment variables, the directory i checked doesn't exist
- python - how can i use the environment variables set in heroku in django's viewspy?
- python - how to share variables with multiprocessing
- python - i want to dynamically change the upload destination with django, modelsimagefield
- get a site to display dynamically with python selenium
- python - i want to import the date and time name file by specifying variables
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- xcode - pod install [!] no `podfile 'found in the project directory