Why is it string.join(list), not list.join(string)?

Asked 2 years ago, Updated 2 years ago, 78 views

I think when we said we were going to make "Hello-world", I think it's better to use it like Source Code 1 Why can't source code 1 be executed and should I use source code 2 together? Is there a reason?

my_list = ["Hello", "world"]
print my_list.join("-")
my_list = ["Hello", "world"]
print "-".join(my_list)

list string python join

2022-09-21 17:01

1 Answers

The reasons are as follows:

all iterable is stories of being able to join a list join, the (string) tup join () , dict join () , join file. () for and so on all iterable join () means should be giving them.

Because you don't have to do this, join() It's the same form as the current str.join()


2022-09-21 17:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.