Is the following python code valid?
class Test:
def __init__(self):
self.number = 5
def returnTest(self):
return Test()
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes it is valid. The class is defined by the time you create an object and call the
returnTestmethod.However, in cases where a method acts like a factory, you might want to consider using the classmethod decorator. When inheritance and other annoyances come in the way, this can help.