![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Do you think declarations within Python class are equivalent to those within __init__ method?
Declarations anywhere in the class(other than in __init__) and declarations in the __init__method are not the same. The following code shows this to be true.
Example
import sys class foo(): print 'within class' def __init__(self): print 'within init' def do_smthng(self): print 'do something' def main(): f=foo() f.do_smthng() return 0 if __name__ == '__main__': sys.exit( main() )
Output
within class within init do something
Advertisements