Python Forum
Default values of arguments with the same id
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Default values of arguments with the same id
#3
(Dec-02-2020, 02:16 PM)stranac Wrote: Ah, the good old mutable defaults...

https://python-forum.io/Thread-Basic-Var...on-Gotchas has an explanation of what's going on.
Search for "empty list".
Thank you for your answer.
According to you, I searched the internet.
And I used the following solution
class test:
    def __init__(self,val=None):
        if val==None:val=[]
        self.val=val
Writing the third line sounds a little silly but I have to.This reduces the readability of Python.
I think for other people with a different id is more useful than the same id.
Reply


Messages In This Thread
RE: Default values of arguments with the same id - by DrVictor - Dec-02-2020, 02:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  What data types can I use for default values? Mark17 1 629 Oct-09-2023, 02:07 PM
Last Post: buran
  Function with many arguments, with some default values medatib531 3 2,728 Mar-14-2020, 02:39 AM
Last Post: medatib531
  Function Default Arguments grkiran2011 7 3,933 Aug-09-2018, 11:12 AM
Last Post: grkiran2011
  Functions (Arguments Passing,Changing a mutable ,Assignment to Arguments Names) Adelton 2 4,013 Mar-02-2017, 10:23 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

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