Python is an interpreted, object-oriented, high-level programming language with dynamic semantics.
For me, Python is the best programming language to start with. It's simple syntax makes Python beginner-friendly.
OOP)?selfself
self - any other name is definitely frowned upon. There are many advantages to using a standard name - any reader of your program will immediately recognize it and even specialized IDEs (Integrated Development Environments) can help you if you use self
Theselfin Python is equivalent to thethispointer in C++ and thethisreference in Java and C#.
Let's look at this simple class
Output:class Person:
def __init__(self, name):
self.name = name
def say_hi(self):
print('Hello, my name is', self.name)
p = Person('Kenan')
p.say_hi()
$ python oop_init.py
Hello, my name is Kenan
__init__ method as taking a parameter name (along with the usual self). Here, we just create a new field also called name. Notice these are two different variables even though they are both called 'name'. There is no problem because the dotted notation self.name means that there is something called "name" that is part of the object called "self" and the other name is a local variable. Since we explicitly indicate which name we are referring to, there is no confusion.p, of the class Person, we do so by using the class name, followed by the arguments in the parentheses: p = Person('Kenan').__init__method. This is the special significance of this method.self.name field in our methods which is demonstrated in the say_hi method.