Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is my string empty?
#6
(Jan-30-2021, 03:52 AM)bowlofred Wrote:
(Jan-30-2021, 02:29 AM)karabakh Wrote: When I add the ids to some list, the list is not being overwritten.

That's because you're using a method of the list that modifies it, like list.append(). What you're not doing is reassigning the list each time through like list = [new_item].

With strings, you'd instead assign the existing part and the new part to a variable. Something like:

full_string = ""
for s in list:
    full_string += s  # Keeps the existing portion each time through the loop.

Thank you. I also discovered extend which seems to be what you are mentioning here.
Reply


Messages In This Thread
Why is my string empty? - by karabakh - Jan-30-2021, 02:12 AM
RE: Why is my string empty? - by bowlofred - Jan-30-2021, 02:24 AM
RE: Why is my string empty? - by karabakh - Jan-30-2021, 02:29 AM
RE: Why is my string empty? - by deanhystad - Jan-30-2021, 02:54 AM
RE: Why is my string empty? - by bowlofred - Jan-30-2021, 03:52 AM
RE: Why is my string empty? - by karabakh - Jan-30-2021, 04:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  -i option changes sys.path (removes leading empty string '') markanth 6 1,995 Aug-26-2022, 09:27 PM
Last Post: markanth
  build a list (add_animals) using a while loop, stop adding when an empty string is en nikhilkumar 1 8,905 Jul-17-2017, 03:29 PM
Last Post: buran
  if line edit is empty put in a string birdieman 5 4,963 Mar-16-2017, 01:52 PM
Last Post: birdieman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020