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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:13:23+00:00 2026-06-05T07:13:23+00:00

I did quite a bit of perusing, but I don’t have a definite answer

  • 0

I did quite a bit of perusing, but I don’t have a definite answer for the concept that I’m trying to understand.

In Python, if I take a list, such as:

L1=['muffins', 'brownies','cookies']

And then attempted to replace the first pointer to an object in the list, namely ‘muffins’ by using the code:

L1[0:1] = 'cake'

I would get a list L1:

['c', 'a', 'k', 'e', 'brownies', 'cookies']

Yet if I took the same list and performed the operation (now with the 4 elements from the string cake):

L1[0:4] = ['cake'] # presumably, it's now passing the string cake within a list? (it passed into the modified list shown above)

I get the output I initially desired:

['cake', 'brownies', 'cookies']

Can anyone explain why that is, exactly?
I’m assuming that when I take cake initially without it being in a “list”, it breaks the string into its individual characters to be stored as references to those characters as opposed to a single reference to a string…

But I’m not entirely sure.

  • 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-05T07:13:24+00:00Added an answer on June 5, 2026 at 7:13 am

    Two important points:

    1. Slice assignment takes an iterable on the right-hand side, and replaces the elements of the slice with the objects produced by the iterable.
    2. In Python, strings are iterable: iterating over a string yields its characters.

    Thus

    L1[0:1] = 'cake'
    

    replaces the first element of L1 with the individual characters of 'cake'.

    To replace the first element with the string 'cake', simply write:

    L1[0] = 'cake'
    

    or, using the slice assignment syntax:

    L1[0:1] = ['cake']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've searched quite a bit and found a few solutions that did not end
I did quite a bit of research on this, but I am having a
I did quite a bit of homework before posting here but still could not
Did quite a bit of research trying to figure out how to get this
Did you ever have the following situation: you need to store information, but a
I did quite a bit of searching around and didn't find anything of much
I'm experimenting with the Async CTP and liking it quite a bit. I did
I have done quite a bit of research on this issue and have not
I don't think I quite understand how exports work in Node.js . In a
I'm programmer-beginner, but I want to understand the things a bit more deeply. I

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.