Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8234367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:27:03+00:00 2026-06-07T18:27:03+00:00

Can someone explain to me why in python when we want to join a

  • 0

Can someone explain to me why in python when we want to join a string we write:

'delim'.join(list)

and when we want to split a string we write:

str.split('delim')

coming from java it seems that one of these is backwards because in java we write:

//split:
str.split('delim');
//join
list.join('delim');

edit:
you are right. join takes a list. (though it doesnt change the question)

Can someone explain to me the rationale behind this API?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:27:06+00:00Added an answer on June 7, 2026 at 6:27 pm

    Join only makes sense when joining some sort of iterable. However, since iterables don’t necessarily contain all strings, putting join as a method on an iterable doesn’t make sense. (what would you expect the result of [1,"baz",my_custom_object,my_list].join("foo") to be?) The only other place to put it is as a string method with the understanding that everything in the iterable is going to be a string. Additionally, putting join as a string method allows it to be used with any iterable — tuples, lists, generators, custom objects which support iteration or even strings.

    Also note that you are completely free to split a string in the same way that you join it:

    list_of_strings='this, is , a, string, separated, by , commas.'.split(',')
    

    Of course, the utility here isn’t quite as easy to see.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone explain this weird behavior of python re? Obviously the string 'test' does
Referring to this Python List Comprehension Vs. Map question, can someone explain why List
Can someone explain to me this odd thing: When in python shell I type
Can someone please explain algorithm for itertools.permutations routine in Python standard lib 2.6? I
Can someone explain why Python does the following? >>> class Foo(object): ... bar =
Can someone explain what the dict class is used for? This snippet is from
>> type countlines.py | python countlines.py Can someone explain the what type does? Does
I'm sure it's intentional, so can someone explain the rationale for this behavior: Python
The following is a python code using the subprocess module. Can someone explain what
Can someone explain this (straight from the docs - emphasis mine): math.ceil(x) Return the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.