Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

464
Views
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 answers
Answer question

0

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

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!