How can i copy a class with change some default parameters

class name1():
    
    def __init__(self, var1, var2, var3 = 3, var4 = 4, var5 = 5):
        self.var1 = var1
        self.var2 = var2
        self.var3 = var3
        self.var4 = var4
        self.var5 = var5

simply I want to copy the name1 class with change var3 = 10 and var5 = 20

Example: name2 = name1 class with change var3 = 10 and var5 = 20

After Change


name2(var1, var2, var3 = 10, var4 = 4, var5 = 20)

var1 and var2 are required positional arguments. You have to pass something in there. The remaining parameters are keyword arguments with defaults, so you can replace the defaults with new assignments:

class Name:
    # insert your __init__ code from above here
    ...


name2 = Name("foo", "bar", var3=10, var5=20)

If you only want to pass in two specific arguments, consider making all parameters keyword arguments:

class Name:

    def __init__(self, var1=None, var2=None, var3=3, ...):
        ...


name3 = Name(var3=10, var5=20)

I don’t want create class instance just want copy the class with change some default parameters.

Note, you are creating instance attributes (via __init__). You seem to want to change on a copy of the class, not the instance.

Option 1 - A simple approach is to make a new class. (NotImplemented)

Option 2 - Another approach is to subclass a base class.

class Student:
    
    def __init__(self, first, last, age=18, year=2020, major=None):
        self.first = first
        self.last = last
        self.age = age
        self.year = year
        self.major = major


class MusicStudent(Student):
    
    def __init__(self, *args, year=2023, major="music", **kwargs):
        super().__init__(*args, year=2023, major="music", **kwargs)

Demo

s = Student("John", "Doe")
s.first, s.year, s.major
# ('John', 2020, None)

ms = MusicStudent("Jane", "Doe")
ms.first, ms.year, ms.major
# ('Jane', 2023, 'music')

Option 3 - Another option is to make a class factory:

def student_factory(age, year, major):
    """Return a custom Student class."""
    class Student:

        def __init__(self, first, last, age=age, year=year, major=major):
            self.first = first
            self.last = last
            self.age = age
            self.year = year
            self.major = major
        
    return Student

Demo

UndeclaredStudent = student_factory(18, 2020, None)
MusicStudent = student_factory(20, 2022, "music")

us = Student("John", "Doe")
us.first, us.age, us.year, us.major
# ('John', 18, 2020, None)

ms = MusicStudent("Jane", "Doe")
ms.first, ms.age, ms.year, ms.major
# ('Jane', 20, 2022, 'music')

There might be other options, but you may need to expound on exactly what you want, perhaps with more examples.

Imran Khan said:
“I don’t want create class instance just want copy the class with
change some default parameters.”

I don’t understand your question. If you aren’t making any instances,
why do you need the class?

“Copy the class” is easy: use the mouse to select the text of the class,
copy it, then paste it. But I don’t think that’s what you want.

I think that you need to explain what you want to do, and we can suggest
a solution. You have a class:

class A:
    def __init__(self, x, y, z): pass

Give us a concrete example of what comes next: you make a copy, and then
what? What do you do with it? Do any methods change other than
__init__?

If the only difference is you want to add new default values to the
__init__ method, there are two simple solutions. One is a wrapper
function:

def wrapper(x=1, y=2, z=3):
    return A(x, y, z)

and the other is inheritance:

class B(A):
    def __init__(self, x=1, y=2, z=3):
        super().__init__(x, y, z)

If you need something else, I have no idea what it could be, so you will
have to explain what your requirements are.