Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

How does .join work in Python?

I want to display each row of a SQL query result on a webpage. I found some code, but I don't understand what this line does.

u"<br>".join([u"{0}".format(row.combination) for row in salt])

How does the .join method give me the desired result?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Best to run a python shell and test it, such as:

>>> "x".join (["a", "b", "c"])
'axbxc'
>>> "abc".join (["M"])
'M'

The "x" was used as the thing in between the values in the iterable. Next time "abc" was used in between, except there was only one value, so there was no in between needed.

Then refer to the docs as per CoryKramer comment.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...