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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:38:22+00:00 2026-06-08T09:38:22+00:00

I would think that if i did the following code in python var =

  • 0

I would think that if i did the following code in python

var = [0].extend(range(1,10))

then var would be a list with the values 0 – 9 in it.

What gives?

  • 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-08T09:38:26+00:00Added an answer on June 8, 2026 at 9:38 am

    As Oscar López and others have already explained, extend is a command, which returns None, to abide by command/query separation.

    They’ve all suggested fixing this by using extend as a command, as intended. But there’s an alternative: use a query instead:

    >>> var = [0] + range(1, 10)
    

    It’s important to understand the difference here. extend modifies your [0], turning it into [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. But the + operator leaves your [0] alone, and returns a new list [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].

    In cases where you’ve got other references to the list and want to change them all, obviously you need extend.

    However, in cases where you’re just using [0] as a value, using + not only allows you to write compact, fluid code (as you were trying to), it also avoids mutating values. This means the same code works if you’re using immutable values (like tuples) instead of lists, but more importantly, it’s critical to a style of functional programming that avoids side effects. (There are many reasons this style is useful, but one obvious one is that immutable objects and side-effect-free functions are inherently thread-safe.)

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

Sidebar

Related Questions

I got some code that i did 3 years ago under python 2.5 or
You would think that launching a bat file from Java would be an easy
From what I've read from Herb Sutter and others you would think that volatile
I keep getting a NullReferenceException on the su.Companies.Add(co); line. I would think that with
My problem is one that you would think is quite common, but I haven't
First off I would like to say that I think that my question may
I'm trying to do something that i would think to be rather simple. I
So I have this idea for a RubyGem that I think would be an
I would like to know if ParseExact is faster than Parse. I think that
I am trying to write a very thin hypervisor that would have the following

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.