Quick actions

cmd+k|ctrl+k

Navigation

Languages

FixMutableDefaultArgumentIssue

Snippet info

Language

Python

Visibility

public

Author

masterhun

Created

2023-09-08T21:43:30.89639Z

Updated

2023-09-08T21:47:58.987961Z


# Title: "Python None Keyword Usage [Practical Examples]"
# URL: https://www.golinuxcloud.com/python-none-examples/

print("Using Python None to fix the mutable default argument issue")

# An example of the problem, not the solution

# python function
def Student(name, details=[]):
    # appending the value to the list
    details.append(name)
    # return the list
    return details

# assigning the name
name1 = "Bashir"
name2 = "Alam"

# calling the function
student1 = Student(name1)
student2 = Student(name2)

# printing
print(student1)
print(student2)


"""

The output is as follows: 

Using Python None to fix the mutable default argument issue
['Bashir', 'Alam']
['Bashir', 'Alam']

"""

INFO