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 7004979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:16:10+00:00 2026-05-27T21:16:10+00:00

These work: >>> print [1,2,3] + [4,5] [1,2,3,4,5] >>> ‘abc’.upper() ‘ABC’ This doesn’t: >>>

  • 0

These work:

>>> print [1,2,3] + [4,5]
[1,2,3,4,5]
>>> 'abc'.upper()
'ABC'

This doesn’t:

>>> print [1,2,3].extend([4,5])
None

Why? You can use string methods on bare strings, so why can’t you use methods on bare sequence types such as lists? Even this doesn’t work:

>>> print list([1,2,3]).extend([4,5])
None

N.B. For a colloquial meaning of ‘work’. Of course there’ll be a good reason why my expected behaviour is incorrect. I’m just curious what it is.


P.S. I’ve accepted soulcheck’s answer below, and he is right, but on investigating how the addition operator is implemented I just found that the following works:

>>> [1,2,3].__add__([4,5])
[1, 2, 3, 4, 5]

But presumably the add method doesn’t modify the underlying object and creates a new one to return, like string methods.

  • 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-05-27T21:16:11+00:00Added an answer on May 27, 2026 at 9:16 pm

    extend works, just doesn’t return any value as it’s modifying the object it works on. That’s a python convention to not return any value from methods that modify the object they’re called on.

    Try:

     a = [1,2,3]
     a.extend([4,5])
     print a
    

    edit:

    As for why one reason for this could be that it’s sometimes ambigous what the method should return. Should list.extend return the extended list? A boolean? New list size?

    Also it’s an implementation of command-query separation, ie. if it returned something it would be a query and command in one and cqs says it’s evil (although sometimes handy – see list.pop()).

    So generally you shouldn’t return anything from mutators, but as with almost everything in python it’s just a guideline.

    list.__add__() is the method called when you do + on lists – it returns a new list.

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

Sidebar

Related Questions

I need to change an element's ID using jQuery. Apparently these don't work: jQuery(this).prev(li).attr(id)=newid
Intro I work in a facility where we have microscopes. These guys can be
In Javascript, we can call methods on string literals directly without enclosing it within
I can't seem to get this toString() method to work? The deepToString method works
I've got a site that provides blog-friendly widgets via JavaScript. These work fine in
$('#menu .sub-right').css( 'paddingLeft', $('#menu .sub-left').width() ); nor $('#menu .sub-right').css({'padding-left': $('#menu .sub-left').width()}); ...these work. What
I have created custom MembershipUser, MembershipProvider and RolePrivoder classes. These all work and I
I'm looking for a tutorial explaining how to work with these 3 technologies, found
We're having a hard time figuring how these credentials objects work. In fact, they
I work in a medium sized team and I run into these painfully large

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.