Created
November 10, 2017 09:10
-
-
Save MishraKhushbu/a98f787f22076c8bade60bd99312c4f0 to your computer and use it in GitHub Desktop.
Basics OOOOPs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__INIT__: | |
The name __init__ is essentially reserved in python , special function or method.What's special about it ? Creates space in memory or initialzes | |
for class to remeber details of class attributes or variables. | |
class movie(): | |
def __init__(self,title,story): | |
self.title = "hero" | |
self.storyline = "drama" | |
somehow initialize these variable(title,story) with information init is going to receive.And in particular it is going to receive the information while | |
object creation of class | |
----------Example of self and without self-------------------- | |
print "Hello World!\n" | |
class foo: | |
x = 'original class' | |
c1 ,c2 = foo(),foo() | |
c1.x = 'changed instance' | |
print c1.x #output changed instance | |
print c2.x # output original instance | |
foo.x = 'class instance changed' | |
print c2.x # output class instance changed | |
print c1.x # changed instnce | |
# above code of piece is also called staic method | |
class withself(): | |
def __init__(self): | |
self.x = 'with self' | |
d1 = withself() | |
print d1.x # output with self | |
withself.x = 'class with self' | |
print withself.x # ouput class with self | |
************************************ | |
1.Basically this program teaches the use of self and without self , which flows | |
with the concept of | |
static attributes. | |
2.without using the 'self parameter' the attributes will be called as static and | |
can't be changed once created | |
**************************************************************************************** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment