How to combine multiple print outputs into an array in python

不言
Release: 2018-04-19 10:59:49
Original
3209 people have browsed it

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))
Copy after login

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
Copy after login

If we modify the above code segment as follows:

 for i in range(10):
 print ("\"%s\"," % (f_list[i].name)),
Copy after login

The execution result of the code becomes the following:

"f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10",
Copy after login

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"]
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template