I'm new to python. It may be a very rudimentary question,
Please be kind to me. ..
I want to call num1 to num3 as below dynamically.
(Turn the for statement and output the value by referring to num1 to 3)
I was wondering if I could do it with the following code, but num is a variable
It doesn't seem to work.
I know you can do it by putting it in an array,
This time, I'm looking for a program that needs to be assigned to a variable.
I did a lot of research, but I didn't understand ...
Should I use eval or exec?
I wanted to write code using eval and exec,
I don't understand the meaning of such a built-in function, and I didn't know how to write it.
I'm sorry if you're a beginner and have heard something you don't understand.
I would be grateful if you could give me any advice.
num1 = A num2 = B num3 = C for i range (1,4): num ='num' + str (i) print (num)
Answer # 1
print (eval (num))
Answer # 2
Let's use an array
Then you can specify it with a variable
Answer # 3
list) Is used.
nums = [None, A, B, C] for i in range (1,4): num = nums [i] print (num)
- i want to change the row value using the value of the previous row in python: pandasdataframe
- python - i want to dynamically change the upload destination with django, modelsimagefield
- python 3x - i want to save the value of a variable in memory
- i want to change the value of an element of a multidimensional array in python
- about the phenomenon that the value of the variable (list object including map) is reset in python 38
- python - i want to change the value of the list using a function
- python - i want to change the ip address that the django app gets by default from remote_addr to http_x_forwarded_for in middlew
- i want to set the maximum value of the slider in python to the number entered in the text box
- c # - how to deposit a value in a static variable and retrieve it again
- i want to declare variables dynamically in python
- java - i want to change the html id dynamically with thymeleaf
- i want to change the default version of python
- c # - navmeshagent value does not change
- python - does pixel information change when cv2imwrite processing is performed?
- python 3x - change row name/column name of csv file
- if you change the value of the select box, the item of another select box will switch automatically jquery
- python - how to output the key and value in the dictionary in any form
- python 3x - how to get the value of scrolledtext
- i want to get the value from a constant in python and display it
- 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