Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

self keyword in python

class Person:
  def __init__(mysillyobject, name, age):
    mysillyobject.name = name
    mysillyobject.age = age

  def myfunc(abc):
    print("Hello my name is " + abc.name)

p1 = Person("John", 36)
p1.myfunc()

#self represents the instance of the class. By using the “self” keyword we can access the attributes and methods of the class in python. It binds the attributes with the given arguments. The reason you need to use self. is because Python does not use the @ syntax to refer to instance attributes
Comment

self keyword in python

self keyword
Comment

PREVIOUS NEXT
Code Example
Python :: string pythhon 
Python :: python convert time 
Python :: how to use python all() function to check a list is empty or not 
Python :: instance of object 
Python :: add an item to a dictionary python 
Python :: solving linear equation using numpy 
Python :: how to connect mongodb database with python 
Python :: python numpy delete column 
Python :: linked list python 
Python :: pandas drop rows 
Python :: pk django 
Python :: turn list into string 
Python :: how to make a label in python 
Python :: tuple python 
Python :: manual merge sort 
Python :: map python 
Python :: sys.argv python example 
Python :: for loop practice problems python 
Python :: python add encoding for non-English language like Arabic 
Python :: convert from R to python 
Python :: doormat pattern 
Python :: pandas math operation from string 
Python :: transpose([[1],[2],[3]]) 
Python :: pythoon 
Python :: adding if statements in pyhton with tuple 
Python :: tekinter python 
Python :: pip_install_packages2.bat 
Python :: "Token" is not defined Pylance 
Python :: integer to binary python 16 bit 
Python :: custom Yolo object detection python 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =