Created
July 24, 2018 18:53
-
-
Save FeraruSilviuMarian/2881ac06b08f92b51f948ee21538de0e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class TestClass: | |
def __init__(self, someString): | |
self.someString = someString # an instance variable | |
def test(): | |
print('Test') | |
# uppon creating an instance of TestClass called obj0 | |
# the special function __init__ is called | |
# in this function obj0 is passed as an argument named self | |
# and a string is also passed named someString | |
obj0 = TestClass('some string') | |
# the operation bellow isn't valid because obj0 will be passed as an argument into the method test | |
# however, as seen in the definition of test, the method test does not define any parameter. | |
obj0.test() # comment this line after you see the error it produces | |
# in order to call the method test, we either have to define it with at least one parameter | |
# conventionally called self | |
# or we can call it from the class itself | |
# however, it won't be able to access any instance variable this way | |
TestClass.test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment