Home > Article > Backend Development > How to combine multiple print outputs into an array in python
Below I will share with you an article in Python that combines multiple print outputs into an array. It has a good reference value and I hope it will be helpful to everyone. Let’s take a look together
For example, there is the following piece of code:
for i in range(10): print ("%s" % (f_list[i].name))
This code The execution of the segment will generate the following 10 lines of "name" attribute string
f1 f2 f3 f4 f5 f6 f7 f8 f9 f10
If we modify the above code segment as follows:
for i in range(10): print ("\"%s\"," % (f_list[i].name)),
The execution result of the code becomes the following:
"f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10",
In this way, we can use the above execution results to construct the required array. For example:
flowNameList = ["f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10"]
Note:
A comma is added at the end of the print statement ',' is to prevent the print output from wrapping;
To output double quotes '"', the escape character '\"' is required.
Related recommendations:
Python implements reading strings and distributing them by columns and then outputting them by rows
The above is the detailed content of How to combine multiple print outputs into an array in python. For more information, please follow other related articles on the PHP Chinese website!