Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Global vs. Local Variables
#2
Are you looking for something like this?
A = []

def update_dict(dname, value, clear=False):
    if clear:
        dname = []
    dname.append(value)
    print(f"Dict contents: {dname}")


update_dict(A, 44)
update_dict(A, 35)
update_dict(A, 55, clear=True)
Output:
Dict contents: [44] Dict contents: [44, 35] Dict contents: [55]
Davy_Jones_XIV likes this post
Reply


Messages In This Thread
Global vs. Local Variables - by Davy_Jones_XIV - Jan-06-2021, 09:18 PM
RE: Global vs. Local Variables - by Larz60+ - Jan-06-2021, 09:54 PM
RE: Global vs. Local Variables - by buran - Jan-06-2021, 09:54 PM
RE: Global vs. Local Variables - by deanhystad - Jan-06-2021, 10:06 PM
RE: Global vs. Local Variables - by Davy_Jones_XIV - Jan-06-2021, 10:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  It's saying my global variable is a local variable Radical 5 1,187 Oct-02-2023, 12:57 AM
Last Post: deanhystad
  Trying to understand global variables 357mag 5 1,143 May-12-2023, 04:16 PM
Last Post: deanhystad
  Delete all Excel named ranges (local and global scope) pfdjhfuys 2 1,807 Mar-24-2023, 01:32 PM
Last Post: pfdjhfuys
  Global variables or local accessible caslor 4 1,040 Jan-27-2023, 05:32 PM
Last Post: caslor
  global variables HeinKurz 3 1,162 Jan-17-2023, 06:58 PM
Last Post: HeinKurz
  How to use global value or local value sabuzaki 4 1,167 Jan-11-2023, 11:59 AM
Last Post: Gribouillis
  Clarity on global variables JonWayn 2 960 Nov-26-2022, 12:10 PM
Last Post: JonWayn
  Global variables not working hobbyist 9 4,754 Jan-16-2021, 03:17 PM
Last Post: jefsummers
  Global - local variables Motorhomer14 11 4,282 Dec-17-2020, 06:40 PM
Last Post: Motorhomer14
  from global space to local space Skaperen 4 2,335 Sep-08-2020, 04:59 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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