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

  • SEARCH
  • Home
  • 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 7760001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:46:08+00:00 2026-06-01T13:46:08+00:00

How does string.join resolve? I tried using it as below: import string list_of_str =

  • 0

How does string.join resolve? I tried using it as below:

import string 
list_of_str = ['a','b','c'] 
string.join(list_of_str.append('d'))

But got this error instead (exactly the same error in 2.7.2):

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.6/string.py", line 318, in join
    return sep.join(words)
TypeError

The append does happen, as you can see if you try to join list_of_string again:

print string.join(list_of_string)
-->'a b c d'

here’s the code from string.py (couldn’t find the code for the builtin str.join() for sep):

def join(words, sep = ' '):
    """join(list [,sep]) -> string

    Return a string composed of the words in list, with
    intervening occurrences of sep.  The default separator is a
    single space.

    (joinfields and join are synonymous)

    """
    return sep.join(words)

What’s going on here? Is this a bug? If it’s expected behavior, how does it resolve/why does it happen? I feel like I’m either about to learn something interesting about the order in which python executes its functions/methods OR I’ve just hit a historical quirk of Python.


Sidenote: of course it works to just do the append beforehand:

list_of_string.append('d')
print string.join(list_of_string)
-->'a b c d'
  • 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-01T13:46:09+00:00Added an answer on June 1, 2026 at 1:46 pm
    list_of_str.append('d')
    

    does not return the new list_of_str.

    The method append has no return value and so returns None.

    To make it work you can do this:

    >>> import string
    >>> list_of_str = ['a','b','c']
    >>> string.join(list_of_str + ['d'])
    

    Although that is not very Pythonic and there is no need to import string… this way is better:

    >>> list_of_str = ['a','b','c']
    >>> ''.join(list_of_str + ['d'])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title says: Why does string.Join need to take an array instead of
this compiles :-) string name; name = 1; this does not: string name =
I seen this code a=a.join().split(); What does this code do? I think a was
I essentially want to do this: if(obj is IDictionary) { return { + string.Join(Environment.NewLine,
I have tried this: public static class ListHelper { public static string ToString<T>(this IList<String>
I have this controller: public ActionResult Details(String UserName) { using (var db = new
I saw this answer of how to join String[] to comma separated string. However
Does string immutability work by statement, or by strings within a statement? For example,
Does String.ToLower() return the same reference (e.g. without allocating any new memory) if all
What does the [string] indexer of Dictionary return when the key doesn't exist in

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.