Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

467
Vistas
Python empty constructor

Is there any way to create an empty constructor in python. I have a class:

class Point:
    def __init__(self, x, y, z):
        self.x = x
        self.y = y
        self.z = z

now I initialize it like this:

p = Point(0, 5, 10)

How can I create an empty constructor and initialize it like this:

p = Point()
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

class Point:
    def __init__(self):
        pass
over 4 years ago · Santiago Trujillo Denunciar

0

As @jonrsharpe said in comments, you can use the default arguments.

class Point:
    def __init__(self, x=0, y=0, z=0):
        self.x = x
        self.y = y
        self.z = z

Now you can call Point()

over 4 years ago · Santiago Trujillo Denunciar

0

You can achieve your desired results by constructing the class in a slightly different manner.

class Point:
    def __init__(self):
        pass

    def setvalues(self, x, y, z):
        self.x = x
        self.y = y
        self.z = z
    
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda