Python .join or string concatenation

后端 未结 6 688
小蘑菇
小蘑菇 2021-01-31 18:23

I realise that if you have an iterable you should always use .join(iterable) instead of for x in y: str += x. But if there\'s only a fixed number of va

6条回答
  •  盖世英雄少女心
    2021-01-31 19:04

    I take the question to mean: "Is it ok to do this:"

    ret = user + '@' + host
    

    ..and the answer is yes. That is perfectly fine.

    You should, of course, be aware of the cool formatting stuff you can do in Python, and you should be aware that for long lists, "join" is the way to go, but for a simple situation like this, what you have is exactly right. It's simple and clear, and performance will not be an issue.

提交回复
热议问题