Python Forum
How to append to list a function output?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to append to list a function output?
#5
You have wrong assumptions how for-loop works. I advise to use built-in help for getting basic understanding:

>>> help('for')
The "for" statement
*******************

The "for" statement is used to iterate over the elements of a sequence
(such as a string, tuple or list) or other iterable object:

   for_stmt ::= "for" target_list "in" expression_list ":" suite
                ["else" ":" suite]

/.../

The for-loop makes assignments to the variables(s) in the target list.
This overwrites all previous assignments to those variables including
those made in the suite of the for-loop:

   for i in range(10):
       print(i)
       i = 5             # this will not affect the for-loop
                         # because i will be overwritten with the next
                         # index in the range
/.../  # press Q to exit help
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: How to append to list a function output? - by perfringo - Aug-24-2020, 10:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  append str to list in dataclass flash77 6 495 Mar-14-2024, 06:26 PM
Last Post: flash77
  problem in output of a function akbarza 9 1,209 Sep-29-2023, 11:13 AM
Last Post: snippsat
Question How to append integers from file to list? Milan 8 1,456 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
  How to print the output of a defined function bshoushtarian 4 1,318 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  read a text file, find all integers, append to list oldtrafford 12 3,616 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  Using .append() with list vs dataframe Mark17 7 10,526 Jun-12-2022, 06:54 PM
Last Post: Mark17
  sum() list from SQLAlchemy output Personne 5 4,478 May-17-2022, 12:25 AM
Last Post: Personne
  output correction using print() function afefDXCTN 3 11,110 Sep-18-2021, 06:57 PM
Last Post: Sky_Mx
  python prints none in function output chairmanme0wme0w 3 2,232 Jul-07-2021, 05:18 PM
Last Post: deanhystad
  print function output wrong with strings. mposwal 5 3,135 Feb-12-2021, 09:04 AM
Last Post: DPaul

Forum Jump:

User Panel Messages

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