Interview Question






Comment hidden because of low score. Click to expand.
0
of 0 vote

1) return value of __init__ is None
2) On class object creation __init__ is called by default (similar to constructor in CPP). You can put ur code in def __init__(self) method too which will get called on object creation

3) you can also call __init__ method anywhere using
self.__init__()

- alp April 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

thanks for replying.
can we call the __init_ outside the class?if not then why not?

if we do not provide __init_ definition would there be any default init operator as cpp makes(default constructor)?

- Anonymous April 09, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

could not get 1st query... 'can we call the __init_ outside the class' . if you defined inside class...then only way to call is through class instance object ( automatically ) or by self.__init__()

from python org docs :-
"Class objects are described below. When a class object is called, a new class instance (also described below) is created and returned. This implies a call to the class’s __init__() method if it has one. Any arguments are passed on to the __init__() method. If there is no __init__() method, the class must be called without arguments."
so even if you don't create it it will be called

- alp April 09, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

so that means there is default __init__( ) method.If we do not provide any init() there will be a init() method( as cpp gives default constructor).
Am I right?

what I meant in first query was:-
__init__ is private function.But python does not give any concept of private.
Its just name mangling.So by resolving name mangling we should be able to call init().
But when I tried I was not able to call.

- Anonymous April 10, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

There's no default __init__()

- AlexB March 19, 2012 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More