a = 1 for i in range (1,4): a = a + i print (a) # 1 a # 2
It is a program that calculates the addition of the above arithmetic progression with the for syntax.
I would like to retrieve the list [(i, a) = (1,2), (2,4), (3,7)].
in the for syntax
print (a) # 1
Is displayed, but outside the for syntax
a # 2
Is just output.
How can I retrieve the list [(i, a)]?
Answer # 1
ks =  # difference list a = 1 for i in range (1, 4): a = a + i ks.append ((i, a)) print (ks) # [(1, 2), (2, 4), (3, 7)]
- python - difference between pandas dataframeplotbar and dataframeplot (kind = bar)
- php calculate the difference between the elements of a two-dimensional array
- how to align the number of elements with overlaplengt of python etc
- python - i want to create a binary mask by comparing two elements and setting the smaller one to 0
- python - i want to calculate all the elements in the list and rotate them
- python - list comprehension? how to retrieve the value of
- python - i want to retrieve only even values in the list using an if statement
- some elements cannot be clicked in python selenium (chrome)
- python - combination/multiplication of list elements
- python - array elements cannot be used as function arguments ??
- python - i want to get the elements in the linked site
- python 3x - difference between your own code and the correct code
- python - kivy: to refer to other widget elements
- i want to retrieve a cell value from python
- when graphing a list with matplotlib in python, the number of elements is large and the graph is not displayed
- python - i want to retrieve the element above the element searched by soupfind_all in beautiful soup
- python - i want to get multiple elements with selenium
- python - what is the difference between the two jupyter kernels generated by conda?
- python - elements cannot be acquired after screen transition in selenium